JY2k
JY2k

Reputation: 2909

Android reversing animation

I placed an ImageView in the centre of the screen. I then wanted to animate it from the bottom to the centre. I reasoned to move it without delay out of the screen and then back the same value which would end in the centre. However, the animation makes it so the view will exit from top.

mLogoIV.animate().translationY(1000f).setListener(new AnimatorListenerAdapter() {
    @Override
    public void onAnimationEnd(Animator animation) {
        super.onAnimationEnd(animation);
        mLogoIV.animate().translationY(-1000f).setDuration(3000);
    }
});

Upvotes: 1

Views: 1368

Answers (2)

Saurabh Padwekar
Saurabh Padwekar

Reputation: 4074

Use Object animator.

ObjectAnimator objectAnimator= ObjectAnimator.ofFloat(mLogoIV, "translationY", -750, 0);
                    objectAnimator.setDuration(1000);
                    objectAnimator.start();

Upvotes: 0

Blundell
Blundell

Reputation: 76574

use translationYBy( to animate relative to the current position

https://developer.android.com/reference/android/view/ViewPropertyAnimator.html#translationYBy(float)

mLogoIV.animate().translationYBy(1000f).setListener(new AnimatorListenerAdapter() {
    @Override
    public void onAnimationEnd(Animator animation) {
        super.onAnimationEnd(animation);
        mLogoIV.animate().translationYBy(-1000f).setDuration(3000);
    }
});

From the docs:

The amount to be animated by, as an offset from the current value.

vs what you are doing now:

The value to be animated to.

Upvotes: 1

Related Questions