你好,游客 登录 注册 搜索
背景:
阅读新闻

Android程序创建启动界面

[日期:2011-08-06] 来源:Linux社区  作者:tsiannian [字体:大 中 小]

一般的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);
	}
}
linux
相关资讯       Android教程 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款