animation.start() or animation.startNow() does not start the animation immediately

对着背影说爱祢 提交于 2020-01-12 20:54:14

问题


I have a strange issue - from time to time the animation that should fade out my control (ImageButton) does not kick in immediately. I am using the fadeout animation to hide it and then in myListener on its end (onAnimationEnd) I put new resource as the image on the button.

Somewhere in my app code:

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

Then in myListener.onAnimationEnd(Animation a):

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

Seems there is a rule that the every 4th or 5th animation does not start ...

Thanks for help!


回答1:


adding

buttons[location].invalidate(); 

after

a.startNow();

has fixed my issue.




回答2:


You can also use

buttons[location].startAnimation(a);


来源:https://stackoverflow.com/questions/3604048/animation-start-or-animation-startnow-does-not-start-the-animation-immediate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!