在我的 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();
但没有成功...
有人知道吗?
谢谢。
最佳答案
尝试取消动画,看看,类似
moveright.cancel();
moveright2.cancel();
moveleft.cancel();
或者也尝试重置
moveright.reset();
类似的
关于java - 如何清除android中的动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18222174/