سؤال

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