Home » Android » android – How do I pause frame animation using AnimationDrawable?

android – How do I pause frame animation using AnimationDrawable?

Posted by: admin June 15, 2020 Leave a comment


How do I pause frame animation using AnimationDrawable?

How to&Answers:

I realize this thread is quite old, but since this was the first answer on Google when I was searching for a way to pause an animation, I’ll just post the solution here for someone else to see.
What you need to do is subclass the animation type you’d like to use and then add methods for pausing and resuming the animation. Here is an example for AlphaAnimation:

public class PausableAlphaAnimation extends AlphaAnimation {

    private long mElapsedAtPause=0;
    private boolean mPaused=false;

    public PausableAlphaAnimation(float fromAlpha, float toAlpha) {
        super(fromAlpha, toAlpha);

    public boolean getTransformation(long currentTime, Transformation outTransformation) { 
        if(mPaused && mElapsedAtPause==0) {
        return super.getTransformation(currentTime, outTransformation);

    public void pause() {

    public void resume() {

This will keep increasing your starttime while the animation is paused, effectively keeping it from finishing and keeping it’s state where it was when you paused.

Hope it helps someone.


From the API:

Animations do not have a pause method.