Android程序创建启动界面


一般的Android应用程序在启动时都会显示一个启动界面,可以显示产品的LOGO,作者的信息或者应用的版本信息等,当然,除了这些,在这段时间内还可以对系统状况进行检测,比如网络是否通,电源是否充足等,或者,预先加载程序所需要的相关数据等。下面我们来看一看怎样制作Splash界面。

首先新建一个splashscreen.xml布局文件,我们已经在res/drawable目录下放置了一张启动图片home_gradient.png:

<LinearLayout android:id="@+id/LinearLayout01"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              xmlns:android="http://schemas.android.com/apk/res/android"
              android:gravity="center|bottom"
              android:background="@drawable/home_gradient"
              android:orientation="vertical">
    <ImageView android:layout_marginTop="-60dip"
               android:paddingLeft="20dip"
               android:paddingRight="20dip"
               android:scaleType="centerInside"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:id="@+id/logo">
    </ImageView>
    <!--
    android:typeface 字体风格
    -->
    <TextView android:text="@+id/TextView01"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_marginTop="20dip"
              android:typeface="serif"
              android:shadowDx="0"
              android:shadowDy="2"
              android:shadowRadius="1"
              android:shadowColor="#FFFFFF"
              android:textColor="@drawable/white"
              android:textSize="20dip"
              android:id="@+id/versionNumber"
              android:gravity="center_horizontal"
              >
    </TextView>
</LinearLayout>

然后我们新建一个SplashScreen类:

package com.uutroy.android.bjtuer;
 
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.graphics.PixelFormat;
import android.os.Bundle;
import android.os.Handler;
import android.view.WindowManager;
import android.widget.TextView;
 
public class SplashScreen extends Activity {
 
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		getWindow().setFormat(PixelFormat.RGBA_8888);
		getWindow().addFlags(WindowManager.LayoutParams.FLAG_DITHER);
 
		setContentView(R.layout.splashscreen);
 
		// Display the current version number
		PackageManager pm = getPackageManager();
		try {
			PackageInfo pi = pm.getPackageInfo("com.uutroy.android.bjtuer", 0);
			TextView versionNumber = (TextView) findViewById(R.id.versionNumber);
			versionNumber.setText("Version " + pi.versionName +"\n"+"天堂皓月");
		} catch (NameNotFoundException e) {
			e.printStackTrace();
		}
 
		new Handler().postDelayed(new Runnable() {
			public void run() {
				/* Create an Intent that will start the Main Activity. */
				Intent mainIntent = new Intent(SplashScreen.this,
						BJTUerActivity.class);
				SplashScreen.this.startActivity(mainIntent);
				SplashScreen.this.finish();
			}
		}, 2500);
	}
}
  • 1
  • 2
  • 下一页

相关内容