0

I have an ImageButton that will show different drawables based on its state(pressed, etc) using selectors. I want play an frame by frame animation on this button on specified time intervals.

Here is the code:

ImageButton btn;
btn.setImageResource(R.drawable.my_anim);
AnimationDrawable ani = (AnimationDrawable)btn.getDrawable();
ani.start();

So the issue is that animation is played only once. And after animation is finished i want to reset the button so that it show different drawables based on its state using selectors. But this is not happening now. After the animation is finished, the selectors never worked again. Although btn onClick event is working.

So, how can i do the above?

MA1
  • 2,767
  • 5
  • 35
  • 51

1 Answers1

1

You need some way to be notified when it completes, then do the code to have happen what you want.
check this out: Android AnimationDrawable and knowing when animation ends

Community
  • 1
  • 1
owen gerig
  • 6,165
  • 6
  • 52
  • 91