java - 如何清除android中的动画?

标签 java android animation

在我的 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/

相关文章:

c# - Xamarin 表格 Android : TabbedPage Font Style

android - 如何将 View 放在 CollapsingToolbarLayout 上方

javascript - SVG 使用 Javascript 将形状平滑地变形为其他预定义的形状

java - 安卓-三星 : Creating Widget with configuration activity fails

java - 使用 Traci4j 在 SUMO 中获取车辆的角度

java - 如何通过套接字 C++ 服务器/Java 客户端发送 int

android - 任何可以导入 3d 对象(带动画)的框架/工具/库?

Java 项目管理员权限 windows 7

没有jquery的Javascript动画

ios - NavigationItem 的 titleView 动画不正确