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, 42f); animation.setDuration(1000); animation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { Float currentValue = (Float) animation.getAnimatedValue...