启动界面Splash Screen在应用程序是很常用的,往往在启动界面中显示产品Logo、公司Logo或者开发者信息,如果应用程序启动时间比较长,那么启动界面就是一个很好的东西,可以让用户耐心等待这段枯燥的时间。
Android 应用程序创建一个启动界面Splash Screen非常简单。布局文件: (splash.xml)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/splash" --资源图片splash.jpg android:gravity="bottom" android:orientation="vertical" ></LinearLayout>
Activity文件:(SplashActivity.java)
package lcl.android.activity;
import lcl.android.R;
import android.content.Intent;import android.os.Bundle;import android.support.v4.app.FragmentActivity;import android.view.View;import android.view.animation.AlphaAnimation;import android.view.animation.Animation;import android.view.animation.Animation.AnimationListener;public class SplashActivity extends FragmentActivity {
@Override protected void onCreate(Bundle arg0) { super.onCreate(arg0); final View view = View.inflate(this, R.layout.splash, null); setContentView(view);// 渐变展示启动屏
AlphaAnimation aa = new AlphaAnimation(0.3f, 1.0f); aa.setDuration(2000); view.startAnimation(aa); aa.setAnimationListener(new AnimationListener() { @Override public void onAnimationEnd(Animation arg0) { redirectTo(); }@Override
public void onAnimationRepeat(Animation animation) { }@Override
public void onAnimationStart(Animation animation) { }});
}/**
* 跳转到... */ private void redirectTo() { Intent intent = new Intent(this, MainActivity.class); startActivity(intent); finish(); }} AndroidManifest.xml<activity
android:name="lcl.android.activity.SplashActivity" android:screenOrientation="portrait" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" > <intent-filter> <action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LAUNCHER" />
</intent-filter></activity>运行效果: