动画效果写在xml里,
在按键的onClickListener里如果写成这样
1
2
3
4
5
6
7
8
|
@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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
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 ); } ); |