Waqar Muhammad
Waqar Muhammad

Reputation: 61

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);
}

Upvotes: 6

Views: 1579

Answers (2)

Attaullah
Attaullah

Reputation: 4021

Try to use this code

toptranslateanimation.setRepeatCount(1);
toptranslateanimation.setRepeatMode(Animation.REVERSE);

Upvotes: 10

Divyang Panchal
Divyang Panchal

Reputation: 1909

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());

Upvotes: 1

Related Questions