What a very clever idea! Android API V11 (Honeycomb) introduced a new technique for animation which (until now) I had pretty much ignored. The new mechanism based on android.animation.Animator allows the creation of very powerful animations with minimal effort.
The basic ideas of property animation have been in use in many areas for some time. Simply specify which property of an object you wish to animate, a start value and and end value. The framework does the rest.
As an example: consider modifying the color of a View component from red to green.
View viewObject = ... ValueAnimator redToGreenAnimator = ObjectAnimator.ofInt(viewObject, "backgroundColor", RED, GREEN); redToGreenAnimator.start();
Once start is called, the ObjectAnimator will update the viewObject once every 10mS for 300mS incrementing the passed in value to move from RED to GREEN over that period. You can modify the the duration of the animation with a simple call to setDuration. The rate at which the updates take place are controlled by an Interpolator. The default being a LinearInterpolator causing updates every 10mS. There are many possible Interpolators such which enable accelerating, deceleration, bouncing and a whole lot more effects to be created.
There are two aspects of property animation that have captured my attention: the wonderful simplicity of the system and the fact that you can animate almost anything which conforms to the Java Bean property naming convention. I have a couple of projects coming up where we will need to do some clever graphical stuff and I’m quite sure I’ll be using property animation as part of the projects. If I find a moment, I’ll post an update as to how well it works under pressure!
If you want to know more about property animation, Learning Tree has a great new course Building Android™ Applications: Extended Features.