动画侦听使用了AnimationListener接口,需要实现三个方法onAnimationStart()、onAnimationRepeat()、onAnimationEnd()
代码:
实现Button的动画侦听
1 findViewById(R.id.btnAnimation).setOnClickListener(new OnClickListener() { 2 3 @Override 4 public void onClick(View v) { 5 // TODO Auto-generated method stub 6 Animation a=AnimationUtils.loadAnimation(getApplicationContext(), R.anim.anim); 7 a.setAnimationListener(new AnimationListener() { 8 9 @Override 10 public void onAnimationStart(Animation animation) { 11 // TODO Auto-generated method stub 12 13 } 14 15 @Override 16 public void onAnimationRepeat(Animation animation) { 17 // TODO Auto-generated method stub 18 19 } 20 21 @Override 22 public void onAnimationEnd(Animation animation) { 23 // TODO Auto-generated method stub 24 Toast.makeText(getApplicationContext(), "Animation End", Toast.LENGTH_SHORT).show(); 25 } 26 }); 27 v.startAnimation(a); 28 } 29 });