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!!

有帮助吗?

解决方案

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 ) 
          {
             ....
          } 
       } 
    } 
); 
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top