在我的 android 应用程序中,我正在使用此代码摇动按钮
public void FlashButton() {
final Button button = ((Button)findViewById(R.id.button_message));
final Animation moveright = AnimationUtils.loadAnimation(this, R.anim.moveright);
final Animation moveleft = AnimationUtils.loadAnimation(this, R.anim.moveleft);
final Animation moveright2 = AnimationUtils.loadAnimation(this, R.anim.moveright2);
AnimationListener animation1Listener = new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {}
@Override
public void onAnimationRepeat(Animation animation) {}
@Override
public void onAnimationEnd(Animation animation) {
button.startAnimation(moveleft);
}
};
AnimationListener animation2Listener = new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {}
@Override
public void onAnimationRepeat(Animation animation) {}
@Override
public void onAnimationEnd(Animation animation) {
button.startAnimation(moveright2);
}
};
AnimationListener animation3Listener = new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {}
@Override
public void onAnimationRepeat(Animation animation) {}
@Override
public void onAnimationEnd(Animation animation) {
button.startAnimation(moveright);
}
};
moveright.setAnimationListener(animation1Listener);
moveleft.setAnimationListener(animation2Listener);
moveright2.setAnimationListener(animation3Listener);
button.startAnimation(moveright);
}
此代码在一个循环中按顺序设置三个动画。
但是如何停止动画,并使按钮再次正常?
我试过.clearAnimation();
了,但是没有用...
有人知道吗?
谢谢。