動畫效果寫在xml裡,
在按鍵的onClickListener裡如果寫成這樣
@Override public void onClick( View v ) { Animation hang_fall = AnimationUtils.loadAnimation( Curriculum.this, R.anim.hang_fall ); v.startAnimation( hang_fall ); Intent i = new Intent( ThisActivity.this, NextActivity.class ); ThisActivity.this.startActivity( i ); }
那麼Intent和animation是同時執行的,看不到動畫效果,
應該這樣寫——加入一個AnimationListener
final ImageView ib = (ImageView)this.findViewById( R.id.photo ); ib.setOnClickListener( new OnClickListener( ) { @Override public void onClick( View v ) { Animation hang_fall = AnimationUtils.loadAnimation(Curriculum.this, R.anim.hang_fall ); hang_fall.setAnimationListener(new Animation.AnimationListener() { public void onAnimationEnd(Animation animation) { Intent i = new Intent( ThisActivity.this, NextActivity.class ); ThisActivity.this.startActivity( i ); } public void onAnimationRepeat(Animation animation) { // Do nothing! } public void onAnimationStart(Animation animation) { // Do nothing! } }); v.startAnimation( hang_fall );} );