How to reset AnimationDrawable

后端 未结 5 1875
粉色の甜心
粉色の甜心 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:32

    android.view.animation.Animation.reset() doesnt work?

    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2020-12-14 15:54

    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.

    0 讨论(0)
  • 2020-12-14 15:54

    You can try public boolean setVisible (boolean visible, boolean restart) and it will play the animation once. For example:

    animationDrawable.setVisible(false, true);
    
    0 讨论(0)
  • 2020-12-14 15:57

    This will send the (AnimationDrawable) timerAnimation to the first frame as soon as stop() has been called:

    timerAnimation.stop();
    timerAnimation.selectDrawable(0);
    
    0 讨论(0)
提交回复
热议问题