Android制作启动界面

制作类似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秒之后发送消息。





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值