android animation with LinearInterpolator

5k views Asked by At

I have some spots, which are buttons, animating vertically from top to the bottom of the screen.
I have implemented the below:

spot.animate().x(x2).y(y2).scaleX(SCALE_X).scaleY(SCALE_Y).setDuration(animationTime).setListener
  (
     new AnimatorListenerAdapter() 
     {
        @Override
        public void onAnimationStart(Animator animation)
        {
            animators.add(animation);
        }
        public void onAnimationEnd(Animator animation)
        {
            animators.remove(animation);
            if (!gamePaused ) 
            {
               ....
            } 
        } 
     } 
  ); 

Question:

I discover that the buttons animating with accelerating speed at the start and decelerating speed upon end of animation.

How could the code be modified with a LinearInterpolator such that the animation is having uniform speed throughout its journey?

Thanks!!

1

There are 1 answers

0
Pavel Dudka On BEST ANSWER

Did you try to use setInterpolator(TimeInterpolator interpolator) method from ViewPropertyAnimator class? So your code would look like:

spot.animate().x(x2).y(y2).scaleX(SCALE_X).scaleY(SCALE_Y).setInterpolator(new LinearInterpolator()).setDuration(animationTime).setListener(
    new AnimatorListenerAdapter() 
    {
       @Override
       public void onAnimationStart(Animator animation)
       {
          animators.add(animation);
       } 

       public void onAnimationEnd(Animator animation)
       {
          animators.remove(animation);

          if (!gamePaused ) 
          {
             ....
          } 
       } 
    } 
);