动画效果写在xml里,
在按键的onClickListener里如果写成这样
2 | public void onClick( View v ) |
4 | Animation hang_fall = AnimationUtils.loadAnimation( Curriculum. this , R.anim.hang_fall ); |
5 | v.startAnimation( hang_fall ); |
6 | Intent i = new Intent( ThisActivity. this , NextActivity. class ); |
7 | ThisActivity. this .startActivity( i ); |
那么Intent和animation是同时执行的,看不到动画效果,
应该这样写——加入一个AnimationListener
01 | final ImageView ib = (ImageView) this .findViewById( R.id.photo ); |
02 | ib.setOnClickListener( new OnClickListener( ) { |
05 | public void onClick( View v ) { |
06 | Animation hang_fall = AnimationUtils.loadAnimation(Curriculum. this , R.anim.hang_fall ); |
07 | hang_fall.setAnimationListener( new Animation.AnimationListener() |
09 | public void onAnimationEnd(Animation animation) |
11 | Intent i = new Intent( ThisActivity. this , NextActivity. class ); |
12 | ThisActivity. this .startActivity( i ); |
15 | public void onAnimationRepeat(Animation animation) |
20 | public void onAnimationStart(Animation animation) |
25 | v.startAnimation( hang_fall ); |