2010-08-30 108 views
3

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

某处在我的应用程序代码:

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(动画):

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

似乎还有的是,每一个第四或第五动画不启动的规则。 ..

感谢您的帮助!

回答

11

加入

buttons[location].invalidate(); 

a.startNow(); 

有固定我的问题。

+5

如果你接受你自己的答案,你会得到一个徽章,而这个问题将不再显示为“不回答”。 – EboMike 2010-09-17 23:56:50

+0

非常感谢它为我工作。 – pvn 2013-02-27 08:34:10

3

您还可以使用

buttons[location].startAnimation(a);