How to remove the slow end of the animation with ObjectAnimator?
Asked Answered
A

1

8

I have this ObjectAnimator:

    cloudAnim2 = ObjectAnimator.ofFloat(cloud2ImageView, "x",500, 1000);
    cloudAnim2.setDuration(3000);
    cloudAnim2.setRepeatCount(ValueAnimator.INFINITE);
    cloudAnim2.setRepeatMode(ValueAnimator.RESTART);        
    cloudAnim2.start();
    cloudAnim2.addListener(new AnimatorListener() {
        @Override
        public void onAnimationCancel(Animator animation) {}
        @Override
        public void onAnimationEnd(Animator animation) {}
        @Override
        public void onAnimationRepeat(Animator animation) {}
        @Override
        public void onAnimationStart(Animator animation) {}
    });

As you can see, the cloud will start of position 500 and will animate to position 1000, and then it will repeat the animation.

The problem is that the animation is becoming slower as it is near his finish. I mean, the speed of the movement is not allways the same.

I want that the speed becomes allways the same. How can this be done?

thanks

Asclepiadean answered 6/7, 2014 at 18:20 Comment(0)
A
17

The default interpolator is AccelerateDecelerateInterpolator, so you will need to set it manually to the LinearInterpolator.

animation.setInterpolator(new LinearInterpolator());
Aculeus answered 7/7, 2014 at 15:47 Comment(2)
I came to the exact same conclusion when with a complex repeating animation using KeyFrames, PVH's and ObjectAnimator.ofPropertyValuesHolder. I always assumed the ObjectAnimator would rely solely on the animators set in the KeyFrame's, but i was really suprised to see a the AccelerateDecelerateInterpolator as default.Mariel
You can also set it to animation.setInterpolator(null);Diction

© 2022 - 2024 — McMap. All rights reserved.