CHAPTER 10: Android Animation: Making Your UI Designs Move 369
Besides having a range, many of the more complex procedural animation transformations involve a
pivot point. A pivot point tells Android how to skew a scale transform favoring a certain area or what
point to rotate around, as you’ll see in a future section when we get into implementing these different
types of transforms using XML.
Like a value range, a pivot point will also require two values to establish. However, unlike a value
range, which utilizes a From and To value, a pivot point uses a two dimensional location on your
display screen, and uses x and y coordinates, just like pixels do, to define where the pivot point is to
be placed within that 2D “plane.” A plane in 2D is like a sheet of paper, or like a layer in compositing,
and is an “infinitely flat” 2D (x and y) surface. By infinitely flat I mean that there is no z dimension
“depth” to the 2D plane.
Pivot points are also used extensively in 3D animation, where setting the pivot point requires three
(x, y, and z) data coordinates in order to be properly specified in 3D space. Currently, Android uses
2D procedural animation in its Animation class, with 3D animation being handled via a different
android.opengl package. Discussion of 3D animation is best-suited for a Pro Android 3D title. In this
book, we are covering 2D, as that is the best starting point to use for absolute beginners!
Let’s take a look at a fourth type of procedural transform, alpha blending, next, and then we will
look at advanced parameters.
Procedural Compositing: Alpha Blending
There is one other attribute which can be animated procedurally in Android, but it is not a
transformation. Alpha blending is much more akin to a compositing feature; in fact, it is a crucial
part of compositing. If you transform an object, the object changes physically in some way, moving it
to a different location (translation), changing its size (scaling), or what direction it is facing or how it is
oriented (rotated).
Alpha blending an object with its background to create procedural animation is done by specifying a
change in the object alpha (transparency) value, with zero being transparent and one being opaque.
This is usually termed as a fade-in or a fade-out in the content production industry, and technically
is compositing. In Android, alpha blending is included with a procedural animation toolset, because
alpha values are logical attributes to animate, especially if you are creating an animated children’s
ghost story, or a transporter beam special effect, or something similar.
You can finely control the Alpha attribute of an object that you are animating procedurally by
using alpha parameters, and you can use an AnimationSet class to seamlessly combine alpha
(transparency) blending with a translation, scale, or rotation transformation. Like most of the other
procedural animation attributes, alpha blending amounts are set using real or floating-point (float)
numbers between 0.0 (transparent) and 1.0 (visible). The exception to this is pivot points, which you
specify using a percentage, such as 50%, and degrees, which you specify using decimal numbers
(floating point, or float values) between 0 and 360 degrees.
It is important to note that using more than one decimal place is allowed when using real or float
values. Thus, if you want the object to be exactly one-third visible, you could use 0.3333 or, for
three-quarters visible, you could specify 0.75 as the starting or ending value for your object’s
alpha value.