CHAPTER 10: Android Animation: Making Your UI Designs Move 387
As you can see in Figure 10-27, the event handling code for imageButtonTwo is error-free, and is
ready to test.
Now if you use the Run As ➤ Android Application menu sequence and test the app, you can click
the first two ImageButton UI elements, which will allow you to switch back and forth between using
the ImageView widget to hold an AnimationDrawable asset and an Animation asset animating a
BitmapDrawable (image) asset. Pretty advanced stuff for an absolute beginner! I guess you are not
an absolute beginner anymore! Next, let’s get really advanced and combine frame animation and
procedural animation, which will give you the maximum amount of power and creative opportunity to
create any animation or special effect that you can imagine!
Hybrid Animation: Using Frames with Tween
To create the spaceship for our Spiral Galaxy M106, we will need to use both an AnimationDrawable
object to hold frames of the pulsing LightShip and an Animation object to apply scale (pulsing),
rotate (spinning), and alpha (fading in and out) transformations using an AnimationSet object.
I am going to attempt to cover everything you’d ever want to know about Android animation in this
chapter, so your apps will be amazing!
- The first thing that you will need to do is to create the XML definition
files for the Animation object as well as the AnimationDrawable object
by right-clicking on the /res/drawable and /res/anim folders and using
the New ➤ Android XML File dialog to create anim_lightship.xml and
anim_lightshipset.xml files. The dialogs with these XML file names and root
element settings ofand are shown in Figure 10-28.
Figure 10-27. The first ImageButton event handler, configured to remove the animation and replace the drawables