Android啟動畫面實現(注:整理于http://www.devdiv.net/bbs/archiver/tid-33217.html)
在應用程序中經常用到啟動畫面,會啟動一個后臺線程為主程序的運行準備資源。
Android要實現啟動畫面可以這樣做:
這是splash.xml布局文件的代碼[code]<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent" android:layout_width="fill_parent" android:orientation="vertical">
<ImageView android:layout_height="fill_parent" android:layout_width="fill_parent" android:scaleType="fitCenter" android:src="@drawable/splash"></ImageView>
</LinearLayout>[/code]
放一個ImageView加載啟動畫面圖片
SplashActivity作為主視圖啟動[code]/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
Handler x = new Handler();
x.postDelayed(new splashhandler(), 2000);
}
class splashhandler implements Runnable{
public void run() {
startActivity(new Intent(getApplication(),MainActivity.class));
SplashActivity.this.finish();
}
}[/code]
Android要實現啟動畫面可以這樣做:
這是splash.xml布局文件的代碼[code]<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent" android:layout_width="fill_parent" android:orientation="vertical">
<ImageView android:layout_height="fill_parent" android:layout_width="fill_parent" android:scaleType="fitCenter" android:src="@drawable/splash"></ImageView>
</LinearLayout>[/code]
放一個ImageView加載啟動畫面圖片
SplashActivity作為主視圖啟動[code]/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
Handler x = new Handler();
x.postDelayed(new splashhandler(), 2000);
}
class splashhandler implements Runnable{
public void run() {
startActivity(new Intent(getApplication(),MainActivity.class));
SplashActivity.this.finish();
}
}[/code]
posted on 2010-11-17 21:44 小一敗涂地 閱讀(1900) 評論(0) 編輯 收藏 所屬分類: android+移動開發