Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TranslateAnimation in reverse position?

I am working on app in which i used TranslateAnimation but i want to reverse TranslateAnimation to start 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);
}
like image 871
Waqar Muhammad Avatar asked May 13 '15 12:05

Waqar Muhammad


2 Answers

Try to use this code

toptranslateanimation.setRepeatCount(1);
toptranslateanimation.setRepeatMode(Animation.REVERSE);
like image 112
Attaullah Avatar answered Oct 11 '22 20:10

Attaullah


use Interpolator for that 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 on your animation you can set your new interpolator:

toptranslateanimation.setInterpolator(new ReverseInterpolator());
like image 25
Divyang Panchal Avatar answered Oct 11 '22 20:10

Divyang Panchal