编写App的开场Activity
在android的app和游戏的应用中,都会有个开场场景,老外管这个叫splash。
现在就编写个简单的SplashActivity
import android.app.Activity;import android.content.Intent;import android.os.Bundle;import android.widget.ImageView;public class SplashActivity extends Activity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.splash);ImageView splashImg = (ImageView) findViewById(R.id.splash_image);splashImg.postDelayed(new Runnable() {//这里利用了View的postDelayedpublic void run() {Intent intent = new Intent();intent.setClass(SplashActivity.this, MainActivity.class);startActivity(intent);finish();}}, 1000);}}
下面是splash.xml,layout 文件了
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" > <ImageView android:id="@+id/splash_background" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:scaleType="fitXY" android:src="@drawable/splash_floor" /> <ImageView android:id="@+id/splash_image" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:scaleType="fitXY" android:src="@drawable/splash_logo" /> <ImageView android:id="@+id/splash_foot" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:layout_marginBottom="10.0dip" android:src="@drawable/splash_logo_foot" /></RelativeLayout>