How to reset AnimationDrawable

后端 未结 5 1889
粉色の甜心
粉色の甜心 2020-12-14 15:01

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

5条回答
  •  无人及你
    2020-12-14 15:44

    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.

提交回复
热议问题