4

在我的 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();了,但是没有用...

有人知道吗?

谢谢。

4

2 回答 2

5

尝试取消动画并查看,例如

 moveright.cancel();
 moveright2.cancel();
 moveleft.cancel();

或者尝试重置

 moveright.reset();

对其他人类似

于 2013-08-14T02:17:56.457 回答
0

如果由于某种原因无法解决问题,我发现启动新的重置类型动画会有所帮助:

.... <scale

android:duration="1"
android:fromXScale="1"
android:fromYScale="1"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="1"
android:toYScale="1" 
android:fillAfter="true"

/> ....

于 2014-04-17T05:22:23.817 回答