I have to animate a circular count down timer and I\'m doing it by animating the background of an ImageView using AnimationDrawable (each image has the according slice of th
android.view.animation.Animation.reset() doesnt work?
I had the same problem where stopping the animation would stop on the current frame. I wanted it to behave like iOS, where stopping would go back to the first frame. This solution works for me:
((AnimationDrawable)(someButton.getBackground())).stop();
someButton.setBackgroundDrawable(null);
someButton.setBackgroundResource(R.drawable.animation);
This first stops it (probably not necessary). Then it kills the background animation. Finally, it recreates the background.
Another possible solution would be to have the same image for the first frame and last frame and do the following instead of calling the stop() method.
((AnimationDrawable)(someButton.getBackground())).setOneShot(true);
if anyone does look into this any further. There is also a method called setVisible(boolean visible, boolean restart). However, that did not work for myself.
You can try public boolean setVisible (boolean visible, boolean restart)
and it will play the animation once. For example:
animationDrawable.setVisible(false, true);
This will send the (AnimationDrawable) timerAnimation
to the first frame as soon as stop()
has been called:
timerAnimation.stop();
timerAnimation.selectDrawable(0);