Android应用启动动画实例

来源:互联网 发布:基于51单片机的设计 编辑:程序博客网 时间:2024/05/21 14:01

Android应用启动主Activity前显示动画

显示欢迎界面并跳转到主界面

首先,创建一个动画layout  startmain.xml

<?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"     android:background="@drawable/bg1"    >   </LinearLayout>
然后在OnCreate中显示动画View

final View view = View.inflate(this, R.layout.startmain, null);setContentView(view);
创建动画类型及时间处理

//渐变展示启动屏AlphaAnimation alphaAnimation = new AlphaAnimation(0.0f,1.0f);alphaAnimation.setDuration(2000);view.startAnimation(alphaAnimation);alphaAnimation.setAnimationListener(new AnimationListener(){@Overridepublic void onAnimationEnd(Animation arg0) {showMainActivity();}@Overridepublic void onAnimationRepeat(Animation animation){}@Overridepublic void onAnimationStart(Animation animation) {}});

动画结束后跳转到主界面

    private void showMainActivity(){                Intent intent = new Intent(this, MainActivity.class);        startActivity(intent);        finish();    }