欢迎界面实现有多种方法,目前了解的实现方法包括(Animation、线程实现、Handle实现)
下面介绍我常用的一种:
首先是欢迎界面的布局.这里就用图片一张:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ff0000"
android:keepScreenOn="true"
android:src="@drawable/wel" />
</LinearLayout>
然后是欢迎界面的activity:
package com.example.welcome;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.MotionEvent;
import android.view.Window;
import android.view.WindowManager;
/**
* 本页主要实现欢迎界面的功能
*/
public class AppWelcomActivity extends Activity {
private static final int INTENT = 1;
private Boolean TOUCH_F = false;
private Handler handler = new Handler() {
public void handleMessage(android.os.Message msg) {
switch (msg.what) {
case INTENT:
Intent intent = new Intent(AppWelcomActivity.this, MainActivity.class);
startActivity(intent);
onDestroy();
break;
}
};
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
this.setContentView(R.layout.app_start_view);
Message message = new Message();
message.what = INTENT;
handler.sendMessageDelayed(message,2000);
}
@Override
protected void onDestroy() {
finish();
super.onDestroy();
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
TOUCH_F = false;
}
return true;
}
}
最后修改AndroidManifest配置文件,把AppWelcomActivity设置成默认:
<activity
android:name="com.example.welcome.AppWelcomActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="MainActivity" android:theme="@style/AppBaseTheme"></activity>