2010-08-30 74 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);