Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reversing an Animation

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?

like image 766
pbreault Avatar asked Nov 08 '10 02:11

pbreault


People also ask

How do I reverse a keyframe?

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.


1 Answers

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()); 
like image 147
pcans Avatar answered Sep 28 '22 17:09

pcans