I have an ImageView that gets animated when it is added to a layout. When it is removed, I want to reverse the same animation.
Is there a way to reverse an animation in android without recoding it and reversing the parameters?
Reverse keyframes In the Keyframe Editor in Motion, drag a selection rectangle to select the keyframes to reverse. Control-click a selected keyframe, then choose Reverse Keyframes from the shortcut menu. The keyframes are reversed.
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());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With