制作类似QQ空间的启动界面一样,提取QQ空间的资源文件。
添加splash.xml文件,添加对应的图片资源。
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffffff" >
<ImageView
android:id="@+id/splashFromNet"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="centerCrop" />
<ImageView
android:id="@+id/logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="-10.0dip"
android:background="@drawable/qz_bg_splashscreen_logo" />
<!--
<ViewStub
android:id="@+id/stub_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginBottom="0.0dip"
android:layout="@layout/qz_viewstub_splash_text" />
-->
</FrameLayout>
定义一个变量一个常量
private Thread thread;
final int CODE=0x101;
在onCreate()方法中添加代码
thread=new Thread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
handler.postDelayed(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
Intent intent=new Intent(SplashActivity.this,Main.class);
startActivity(intent);
finish();
}
},6000);
}
});
thread.start();
新线程延迟3秒后发送Runable对象。
这种方法较为简洁
还有个类似的方法,不过规范一些。
定义变量和常量之后
private Handler handler=new Handler()
{
@Override
public void handleMessage(Message msg) {
// TODO Auto-generated method stub
if(msg.what==CODE)
{
Intent intent=new Intent(SplashActivity.this,Main.class);
startActivity(intent);
finish();
}
super.handleMessage(msg);
}
};
处理接受到的消息如果消息的what值是CODE时启动预设的Activity。
同样在onCreate()方法中
thread=new Thread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
try {
thread.sleep(3500);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
handler.sendEmptyMessage(CODE);
}
});
thread.start();
线程休眠3.5秒之后发送消息。