1. 程式人生 > >Android中設定啟動動畫

Android中設定啟動動畫

  • 以Alphaanimation為例
    思路:在啟動時設定一個Activity作為動畫的載體,在動畫結束後跳轉到另一個介面。
  • XML佈局:在佈局中加入一個ImageView,fill_parent
<ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/welcome"
            android:layout_gravity="center"
            android:src
="@drawable/picture" />
  • 在啟動Activity中
image = (ImageView) findViewById(R.id.welcome);
AnimationSet animationSet = new AnimationSet(true);
AlphaAnimation alphaAnimation = new AlphaAnimation(0,1);
alphaAnimation.setDuration(1000);
animationSet.addAnimation(alphaAnimation);
image.startAnimation(alphaAnimation);
alphaAnimation.setAnimationListener(new
Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { image.setBackgroundResource(R.drawable.welcome); } @Override public void onAnimationEnd(Animation animation) { Intent intent = new
Intent(MainActivity.this, Second.class); startActivity(intent); finish(); } @Override public void onAnimationRepeat(Animation animation) { } });