现在就编写个简单的SplashActivity
import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.widget.ImageView; public class SplashActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.splash); ImageView splashImg = (ImageView) findViewById(R.id.splash_image); splashImg.postDelayed(new Runnable() {//这里利用了View的postDelayed public 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>