6

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);
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
  • it work for me check this link http://stackoverflow.com/questions/7281276/how-to-move-image-up-and-down-continuously-using-translate-animation-in-android] – Mushtaq Rahim May 13 '15 at 12:33

2 Answers2

9

Try to use this code

toptranslateanimation.setRepeatCount(1);
toptranslateanimation.setRepeatMode(Animation.REVERSE);
Attaullah
  • 3,856
  • 3
  • 48
  • 63
1

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());
Divyang Panchal
  • 1,889
  • 1
  • 19
  • 27