【问题标题】:animation.start() or animation.startNow() does not start the animation immediatelyanimation.start() 或 animation.startNow() 不会立即开始动画
【发布时间】:2010-08-30 20:36:41
【问题描述】:

我有一个奇怪的问题 - 有时应该淡出我的控件 (ImageButton) 的动画不会立即启动。我正在使用淡出动画来隐藏它,然后在 myListener 的末尾(onAnimationEnd)我将新资源作为按钮上的图像。

在我的应用代码中的某处:

Animation a = AnimationUtils.loadAnimation(this,R.anim.fadeout); 
a.setAnimationListener(new myListener(location));
buttons[location].setAnimation(a);
a.startNow(); // regardless if its start() or startnNow() 
              // it will work in most of the cases but not 100% reliable
              // I actually can see in debug Log when its late, happens after few more clicks

然后在 myListener.onAnimationEnd(Animation a):

buttons[location].setImageResource(R.drawable.standard_button);

好像有规定每4个或5个动画不开始...

感谢您的帮助!

【问题讨论】:

    标签: android animation android-animation


    【解决方案1】:

    添加

    buttons[location].invalidate(); 
    

    之后

    a.startNow();
    

    解决了我的问题。

    【讨论】:

    • 如果您接受自己的答案,您将获得徽章,并且此问题将不再显示为“未回答”。
    【解决方案2】:

    你也可以使用

    buttons[location].startAnimation(a);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-04-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-29
      • 2015-12-16
      • 2017-07-28
      • 1970-01-01
      相关资源
      最近更新 更多