2010-08-30 9 views
3

J'ai un problème étrange - de temps en temps l'animation qui devrait disparaître de mon contrôle (ImageButton) ne démarre pas immédiatement. J'utilise l'animation fadeout pour la masquer puis dans myListener à sa fin (onAnimationEnd) je mets une nouvelle ressource comme image sur le bouton.animation.start() ou animation.startNow() ne démarre pas l'animation immédiatement

Quelque part dans mon code app:

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 

Puis, en myListener.onAnimationEnd (Animation a):

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

semble qu'il y ait une règle que l'animation chaque 4ème ou 5ème ne démarre pas. ..

Merci pour votre aide!

Répondre

11

ajouter

buttons[location].invalidate(); 

après

a.startNow(); 

a fixé mon problème.

+5

Si vous acceptez votre réponse, vous obtiendrez un badge, et cette question ne montrerez plus comme « sans réponse ». – EboMike

+0

Merci beaucoup cela a fonctionné pour moi. – pvn

3

Vous pouvez également utiliser

buttons[location].startAnimation(a);