TranslateAnimation in reverse position?

I am working on an application in which I used TranslateAnimation, but want to cancel TranslateAnimation to its starting position.

    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);

        setContentView(R.layout.imageviewactivity);

        TranslateAnimation toptranslateanimation = new TranslateAnimation(0, 0, tempBar,
                    scanner_image.getHeight() - 50);
        toptranslateanimation.setDuration(4000);
            toptranslateanimation.setAnimationListener(this);
                scanning_bar.setAnimation(toptranslateanimation);
}
+4
source share
2 answers

Try using this code.

toptranslateanimation.setRepeatCount(1);
toptranslateanimation.setRepeatMode(Animation.REVERSE);
+5
source

use Interpolator for this Like,

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 in the animation you can install a new interpolator:

toptranslateanimation.setInterpolator(new ReverseInterpolator());
+1
source

All Articles