Infinite ObjectAnimator with interpolator... How to accelerate only the initial start?
Asked Answered
T

2

13

I have a object animator with infinite repeat mode. I want to accelerate it only the first time it starts... not every time it is repeating itself

How can this be achieved?

my code:

universeMovement1 = ObjectAnimator.ofFloat(universeImageView, "x", 0, sw);  
        universeMovement1.setDuration(UNIVERSE_MOVEMENT_TIME);
        universeMovement1.setRepeatCount(ObjectAnimator.INFINITE);
        universeMovement1.setRepeatMode(ObjectAnimator.RESTART);
        universeMovement1.setInterpolator(new AccelerateInterpolator());
Tension answered 27/1, 2015 at 18:52 Comment(0)
B
11

Add a listener to your animation with the method onAnimationRepeat and set the interpolator back to LinearInterpolator, or whatever you want. Hence when it repeats it won't accelerate anymore.

animation.addListener(new AnimatorListenerAdapter(){
        @Override
        public void onAnimationRepeat(Animator animation) {
            animation.setInterpolator(new LinearInterpolator());
        }
    });
Barbellate answered 29/1, 2015 at 16:20 Comment(0)
S
0

use this:

objectAnimator.setInterpolator(new LinearInterpolator());
Shellyshelman answered 19/8, 2019 at 15:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.