Reversing an Animation

If you are using Object or ValueAnimator to animate the view, you can simply do

ValueAnimator myAnimator = new ValueAnimator();  
myAnimator.reverse()

Documentation can be found here.


No, sadly you cannot do it with the Animation object. But you can simulate it using an interpolator that will inverse the animation:

package com.example.android;

import android.view.animation.Interpolator;

public class ReverseInterpolator implements Interpolator {
    @Override
    public float getInterpolation(float paramFloat) {
        return Math.abs(paramFloat -1f);
    }
}

Then on your animation you can set your new interpolator:

myAnimation.setInterpolator(new ReverseInterpolator());