当前位置: 编程技术>移动开发
本页文章导读:
▪一个简略的Loading过程 一个简单的Loading过程
实现起来还是比较简单的.看下面的代码.
package com.ql.app;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.Gravity;
import an.........
▪ java获得项目中的文件 java取得项目中的文件
import java.io.IOException;import java.util.Properties;public class FileWriterReader { public static void main(String[] args) { Properties p = new Properties(); try { p.load(FileWriterReader.class.getRe.........
▪ 最近几天突然google地图打不开了 最近几天突然googlemap打不开了
最近几天突然google map打不开了,原因,环境问题。以前每次都根据C盘的用户目录下的.android\debug.keystore创建指纹,然后创建apiKey,以前都成功的,不知怎么搞的,.........
[1]一个简略的Loading过程
来源: 互联网 发布时间: 2014-02-18
一个简单的Loading过程
实现起来还是比较简单的.看下面的代码.
一个比较笨的实现:
http://gundumw100.iteye.com/admin/blogs/1052266
实现起来还是比较简单的.看下面的代码.
package com.ql.app;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.Gravity;
import android.widget.ImageView;
import android.widget.LinearLayout;
public class App extends Activity {
private LinearLayout layout;
private Handler handler;
private int number=10;
private ImageView[] imageViews=new ImageView[number];
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
handler=new Handler(){
@Override
public void handleMessage(Message msg) {
//效率比较低
// for(int i=0;i<number;i++){
// imageViews[i].setBackgroundResource(i==msg.what?R.drawable.progress_go_small:R.drawable.progress_bg_small);
// }
//这样效率高
imageViews[msg.what].setBackgroundResource(R.drawable.progress_go_small);
if(msg.what==0){
msg.what=number;
}
imageViews[msg.what-1].setBackgroundResource(R.drawable.progress_bg_small);
}
};
initViews();
playAnimation();
}
private void initViews(){
layout=(LinearLayout)findViewById(R.id.layout);
LinearLayout container=new LinearLayout(this);
container.setOrientation(LinearLayout.HORIZONTAL);
container.setGravity(Gravity.CENTER);
LinearLayout.LayoutParams lp=new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,LinearLayout.LayoutParams.FILL_PARENT);
lp.gravity=Gravity.CENTER;
LinearLayout.LayoutParams params=new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT);
for(int i=0;i<number;i++){
imageViews[i]=new ImageView(this);
imageViews[i].setBackgroundResource(i==0?R.drawable.progress_go_small:R.drawable.progress_bg_small);
container.addView(imageViews[i], params);
}
layout.addView(container,lp);
}
//不断发送消息,切换图片
private void playAnimation() {
new Thread() {
@Override
public void run() {
while (true) {
for (int i = 0; i < number; i++) {
handler.sendEmptyMessage(i);
try {
this.sleep(300);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}.start();
}
}
一个比较笨的实现:
http://gundumw100.iteye.com/admin/blogs/1052266
[2] java获得项目中的文件
来源: 互联网 发布时间: 2014-02-18
java取得项目中的文件
import java.io.IOException;
import java.util.Properties;
public class FileWriterReader {
public static void main(String[] args) {
Properties p = new Properties();
try {
p.load(FileWriterReader.class.getResourceAsStream("/config_url.properties"));
System.out.println(p.getProperty("ip"));
} catch (IOException e) {
e.printStackTrace();
}
}
}
config_url.properties:
ip=192.168.0.2
java中获取文件路径的几种方式
关于绝对路径和相对路径:
绝对路径就是你的主页上的文件或目录在硬盘上真正的路径,(URL和物理路径)例如:C:xyz est.txt 代表了test.txt文件的绝对路径。http://www.sun.com/index.htm也代表了一个URL绝对路径。相对路径:相对与某个基准目录的路径。包含Web的相对路径(HTML中的相对目录),例如:在Servlet中,"/"代表Web应用的跟目录。和物理路径的相对表示。例如:"./" 代表当前目录,"../"代表上级目录。这种类似的表示,也是属于相对路径。另外关于URI,URL,URN等内容,请参考RFC相关文档标准。RFC 2396: Uniform Resource Identifiers (URI): Generic Syntax,(http://www.ietf.org/rfc/rfc2396.txt)2.关于JSP/Servlet中的相对路径和绝对路径。2.1服务器端的地址服务器端的相对地址指的是相对于你的web应用的地址,这个地址是在服务器端解析的(不同于html和java script 中的相对地址,他们是由客户端浏览器解析的)
第一种:
File f = new File(this.getClass().getResource("/").getPath());
System.out.println(f);
结果:
C:\Documents%20and%20Settings\Administrator\workspace\projectName\bin
获取当前类的所在工程路径;
如果不加“/”
File f = new File(this.getClass().getResource("").getPath());
System.out.println(f);
结果:
C:\Documents%20and%20Settings\Administrator\workspace\projectName\bin\com\test
获取当前类的绝对路径;
第二种:
File directory = new File("");//参数为空
String courseFile = directory.getCanonicalPath() ;
System.out.println(courseFile);
结果:
C:\Documents and Settings\Administrator\workspace\projectName
获取当前类的所在工程路径;
第三种:
URL xmlpath = this.getClass().getClassLoader().getResource("selected.txt");
System.out.println(xmlpath);
结果:
file:/C:/Documents%20and%20Settings/Administrator/workspace/projectName/bin/selected.txt
获取当前工程src目录下selected.txt文件的路径
第四种:
System.out.println(System.getProperty("user.dir"));
结果:
C:\Documents and Settings\Administrator\workspace\projectName
获取当前工程路径
第五种:
System.out.println( System.getProperty("java.class.path"));
结果:
C:\Documents and Settings\Administrator\workspace\projectName\bin
获取当前工程路径
这些都是针对当前工程的,应该还有其他方式的,欢迎补充!
import java.io.IOException;
import java.util.Properties;
public class FileWriterReader {
public static void main(String[] args) {
Properties p = new Properties();
try {
p.load(FileWriterReader.class.getResourceAsStream("/config_url.properties"));
System.out.println(p.getProperty("ip"));
} catch (IOException e) {
e.printStackTrace();
}
}
}
config_url.properties:
ip=192.168.0.2
java中获取文件路径的几种方式
关于绝对路径和相对路径:
绝对路径就是你的主页上的文件或目录在硬盘上真正的路径,(URL和物理路径)例如:C:xyz est.txt 代表了test.txt文件的绝对路径。http://www.sun.com/index.htm也代表了一个URL绝对路径。相对路径:相对与某个基准目录的路径。包含Web的相对路径(HTML中的相对目录),例如:在Servlet中,"/"代表Web应用的跟目录。和物理路径的相对表示。例如:"./" 代表当前目录,"../"代表上级目录。这种类似的表示,也是属于相对路径。另外关于URI,URL,URN等内容,请参考RFC相关文档标准。RFC 2396: Uniform Resource Identifiers (URI): Generic Syntax,(http://www.ietf.org/rfc/rfc2396.txt)2.关于JSP/Servlet中的相对路径和绝对路径。2.1服务器端的地址服务器端的相对地址指的是相对于你的web应用的地址,这个地址是在服务器端解析的(不同于html和java script 中的相对地址,他们是由客户端浏览器解析的)
第一种:
File f = new File(this.getClass().getResource("/").getPath());
System.out.println(f);
结果:
C:\Documents%20and%20Settings\Administrator\workspace\projectName\bin
获取当前类的所在工程路径;
如果不加“/”
File f = new File(this.getClass().getResource("").getPath());
System.out.println(f);
结果:
C:\Documents%20and%20Settings\Administrator\workspace\projectName\bin\com\test
获取当前类的绝对路径;
第二种:
File directory = new File("");//参数为空
String courseFile = directory.getCanonicalPath() ;
System.out.println(courseFile);
结果:
C:\Documents and Settings\Administrator\workspace\projectName
获取当前类的所在工程路径;
第三种:
URL xmlpath = this.getClass().getClassLoader().getResource("selected.txt");
System.out.println(xmlpath);
结果:
file:/C:/Documents%20and%20Settings/Administrator/workspace/projectName/bin/selected.txt
获取当前工程src目录下selected.txt文件的路径
第四种:
System.out.println(System.getProperty("user.dir"));
结果:
C:\Documents and Settings\Administrator\workspace\projectName
获取当前工程路径
第五种:
System.out.println( System.getProperty("java.class.path"));
结果:
C:\Documents and Settings\Administrator\workspace\projectName\bin
获取当前工程路径
这些都是针对当前工程的,应该还有其他方式的,欢迎补充!
[3] 最近几天突然google地图打不开了
来源: 互联网 发布时间: 2014-02-18
最近几天突然googlemap打不开了
最近几天突然google map打不开了,原因,环境问题。以前每次都根据C盘的用户目录下的.android\debug.keystore创建指纹,然后创建apiKey,以前都成功的,不知怎么搞的,突然我的window\preferences\android\build中的default debug keystore的值和C盘下的debug.keystore不一样。导致生产的apiKey不一样。而我每次运行程序时是根据eclipse中的默认的keystore发布的。这样就导致发布时用的debug.keystore文件和生成apiKey的debug.keystore文件不一致。这样地图始终出不来。终于找到原因了。
最新技术文章: