android - animation.start() 或 animation.startNow() 不会立即启动动画

标签 android animation android-animation

我有一个奇怪的问题 - 有时本应淡出我的控件 (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 个动画不开始......

感谢您的帮助!

最佳答案

添加

buttons[location].invalidate(); 

之后

a.startNow();

解决了我的问题。

关于android - animation.start() 或 animation.startNow() 不会立即启动动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3604048/

相关文章:

c# - 在代码问题中应用动画 ScaleTransform

android - 以编程方式为自定义对话框设置动画

android - 淡入淡出动画闪烁 - Android

android - 没有 onTouch 的 CollapsingToolbarLayout?

android - 在 IntentService 中获取地理定位上下文

jQuery:如何仅淡入永久网站元素一次?

Android 后退按钮和 fragment - 动画不起作用

java - Android Studio问题|等待进程出现在设备上超时

java - 应用程序关闭后服务内的功能停止

python - 在 matplotlib 散点图中对标记的大小进行动画处理