animation.start () ou animation.startnow () não inicia a animação imediatamente
-
25-09-2019 - |
Pergunta
Eu tenho um problema estranho - de tempos em tempos, a animação que deve desaparecer meu controle (ImageButton) não entra imediatamente. Estou usando a animação Fadeout para escondê -la e depois em MyListener na extremidade (onanimationend), coloquei um novo recurso como a imagem no botão.
Em algum lugar do meu código de aplicativo:
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
Então, em myListener.onanimationend (Animação A):
buttons[location].setImageResource(R.drawable.standard_button);
Parece que há uma regra de que a 4ª ou 5ª animação não começa ...
Obrigado pela ajuda!
Solução
adicionando
buttons[location].invalidate();
depois
a.startNow();
resolveu meu problema.
Outras dicas
Você também pode usar
buttons[location].startAnimation(a);
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow