A (175)

(Tuis.) #1

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


Notice that my animation duration values “sync” with each other; that is, 4500 goes into 9000
exactly twice and 2250 goes into 9000 four times and into 4500 exactly twice as well.


Setting up Your Hybrid Animation via Java Code


Let’s add this new animation to your Java code next, first by adding an Animation object named
lightShipAnim to hold the animation data that you just created, and then adding method calls inside
of the third ImageButton’s event handling structure to remove the other animation setup(s) and
replace them with your latest creation.



  1. Since you have an Animation object declared, add a comma after
    spaceShipAnim, and add the lightShipAnim to your list of declared Animation
    objects, as shown in Figure 10-35. Then copy and paste the spaceShipAnim
    instantiation line of code again underneath itself, change spaceShipAnim to
    lightShipAnim, and change the R.anim reference from anim_andromeda to
    reference anim_lightshipset instead. The new Animation object instantiation
    code should look like the following:


lightShipAnim = AnimationUtils.loadAnimation(this,R.anim.anim_lightshipset);

Figure 10-35. Add a second lightShipAnim Animation object declaration, and instantiate it using .loadAnimation( )

Free download pdf