Property animation

The second way to manage animations in Android was introduced in Android 3.0 (API level 11). It is designed in a very generic way, so it can handle animations on any property of any object. The system is extensible and lets you animate properties of custom types as well.

There are many ways to use property animations. The simplest one is to use ValueAnimator. This is as easy as defining an animation that goes from one value to another, has a duration, and optionally an interpolator. Then you add a listener that is invoked each time there is a new value, and finally you start the animation.

This code will create a ValueAnimator that animates a float from 0 to 42 along 1,000 milliseconds:

ValueAnimator animation = ValueAnimator.ofFloat(0f, ...

Get Android Game Programming: A Developer’s Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.