CHAPTER 10: Android Animation: Making Your UI Designs Move 379
- To instantiate the spaceShipAnim Animation object, you will set it equal
to the .loadAnimation( ) method call, chained off of the AnimationUtils
class and configured with the current Activity Context object (this) and the
reference to the anim_andromeda XML RotateAnimation object definition
file which you created earlier. Do this using the following single line of Java
programming logic, which is shown error-free in Figure 10-18:
spaceShipAnim = AnimationUtils.loadAnimation(this, R.anim.anim_andromeda);
Figure 10-18. The spaceShipAnim object referencing the anim_andromeda XML transform definition file
Figure 10-19. Declare ImageButton objects; name them imageButtonOne, imageButtonTwo, and imageButtonThree
Now your ImageView and Animation objects have been declared (created) and instantiated (loaded
into system memory). Before we wire them together to make them work together as a team, let’s
continue with the basics and declare and instantiate your three ImageButton objects as well, since
these are going to trigger the app to change between frame animation, tween animation, and hybrid
(frame+tween) animation.
Just like you did with the TextView objects, declare one ImageButton class reference, and give
it three names, imageButtonOne, imageButtonTwo, and imageButtonThree. As you can
see in Figure 10-19, you will need to mouse-over the red error highlight and select the Import
‘ImageButton’ (android.widget) option from a dialog that pops up, so that Eclipse will write the
ImageButton class import statement for you. Effortless Java coding!