A (175)

(Tuis.) #1

370 CHAPTER 10: Android Animation: Making Your UI Designs Move


Set alpha starting and ending values by using the fromAlpha and the toAlpha parameters; so to
fadeout an object, you would set fromAlpha to 1.0, and toAlpha to 0.0, in order to achieve that
fade-out special effect.


To combine multiple different types of procedural animation parameters together, you would create a
“set” for the animation transformation parameters. Using a procedural animation set will allow you
to group transforms and compositing together in a logical and organized fashion. This enables you
to create more complex procedural animation. We will cover how to create procedural animation sets
in detail a bit later on during this chapter.


Procedural Timing: Using Duration and Offsets


You might be wondering how you set the timing which is used between all of these different
range data values. You actually have done this already for your frame animation using the
android:duration parameter, which sets the duration for displaying one single frame. In procedural
animation, duration sets the timing value for a range, and will also to some extent define how many
interpolated data values are created by Android during that range, as well as the duration of each of
the segments between the interpolated values.


It is important to remember that the Android Animation classes decide this value based on the
device’s processing power and what the algorithm (an animation engine) thinks will provide the most
optimal (the smoothest) visual result, given the current processing power to applications in use ratio,
or trade-off.


The duration for any given procedural animation range is set using the duration parameter, which
like it does in frame animation, also takes an integer value in milliseconds. It’s interesting to note that
programming languages such as Java and JavaScript will utilize these millisecond values for all of
their timing functions and operations.


Thus, if you wanted the fade-out we discussed in the previous section to take four seconds, the
XML parameter would be android:duration="4000", since 4000 milliseconds equals 4 seconds. If
you wanted this fade-out to take 4.352 seconds, you would use a millisecond value of 4352, and
thus you have a one-thousandth of a second “granularity,” or level of precision, available for your
procedural animation timing accuracy.


Each transformation (or alpha blend) range that you define has its own separate duration setting,
allowing for a great deal of precision in the XML markup definition of the effect which you are trying
to achieve.


There is one other important timing-related parameter, which allows you to delay when the specified
range will start playback. This is called an animation offset, and it is controlled using the startOffset
parameter data value.


Say you wanted to delay the start of your four second fade-out by four seconds. All you would
have to do is to add the android:startOffset="4000" to your parent tag (which we will be
using for real, a bit later on in the chapter), and this timing delay control would be implemented.
A startOffset parameter is especially useful when utilized in conjunction with looping animation, which
we’re going to be covering next. The reason for this is that when used with animation loop scenarios,
a startOffset parameter will allow you to define a pause during animated element loop cycles. Let’s
take a look at loops next, and parameters for controlling looping animation.

Free download pdf