Android启动画面实现

今天看到网上的启动画面的实现,特此整理收藏:

1、splash.xml布局文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
	android:layout_width="fill_parent" android:layout_height="fill_parent"
	android:orientation="vertical">
	  <ImageView android:layout_width="fill_parent"
	  	android:layout_height="fill_parent" 
	  	android:scaleType="fitCenter"
	  	android:src="@drawable/splash"></ImageView>
</LinearLayout>
 

2、SplashActivity类,使用Handler的postDelayed方法,2秒后执行跳转到主视图

public class SplashActivity extends Activity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.splash);
		new Handler().postDelayed(new Runnable(){
			@Override
			public void run() {
				Intent mainIntent = new Intent(SplashActivity.this,Application.class);
				SplashActivity.this.startActivity(mainIntent);
				SplashActivity.this.finish();
			}
		}, 2000);//2000为间隔的时间-毫秒
	}
}

 3、AndroidManifest.xml配置

    <application android:icon="@drawable/icon" android:label="@string/app_name">  
            <activity android:name=".Application" android:label="@string/app_name">  
                <intent-filter>  
                    <action android:name="android.intent.action.DEFAULT" />  
                    <category android:name="android.intent.category.VIEW" />  
                </intent-filter>  
            </activity>  
            <activity android:name=".SplashActivity" android:label="@string/app_name">  
                <intent-filter>  
                    <action android:name="android.intent.action.MAIN" />  
                    <category android:name="android.intent.category.LAUNCHER" />  
                </intent-filter>  
            </activity>  
        </application>  

  启动OK!

你可能感兴趣的:(android,xml)