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
There are two types of animations that you can do with the view animation framework: Tween animation: Creates an animation by performing a series of transformations on a single image with an Animation. Frame animation: or creates an animation by showing a sequence of images in order with an AnimationDrawable .
A property animation changes a property's (a field in an object) value over a specified length of time. To animate something, you specify the object property that you want to animate, such as an object's position on the screen, how long you want to animate it for, and what values you want to animate between.
The default interpolator is AccelerateDecelerateInterpolator
, so you will need to set it manually to the LinearInterpolator
.
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