Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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());
like image 474
NullPointerException Avatar asked Jan 27 '15 18:01

NullPointerException


1 Answers

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());
        }
    });
like image 126
Whitney Avatar answered Nov 15 '22 18:11

Whitney