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());
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());
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With