Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove the slow end of the animation with ObjectAnimator?

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

like image 900
NullPointerException Avatar asked Jul 06 '14 18:07

NullPointerException


People also ask

What are the two different types of view animation?

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 .

What is property animation?

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.


1 Answers

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

animation.setInterpolator(new LinearInterpolator());
like image 90
Whitney Avatar answered Sep 21 '22 20:09

Whitney