O'Reilly logo

Building Android UIs with Custom Views by Raimon Ràfols Montané

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

ValueAnimator

As part of the property animator system, we have the ValueAnimator class. We can use it to simply animate int, float, or color variables or properties. It's quite easy to use, for instance we can animate a float value from 0 to 360 during 1500 milliseconds using the following code:

ValueAnimator angleAnimator = ValueAnimator.ofFloat(0, 360.f); 
angleAnimator.setDuration(1500); 
angleAnimator.start(); 

This is alright, but if we want to get updates of the animation and react to them, we've got to set an AnimatorUpdateListener():

final ValueAnimator angleAnimator = ValueAnimator.ofFloat(0, 360.f); angleAnimator.setDuration(1500); angleAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required