문제

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