A (175)

(Tuis.) #1
CHAPTER 10: Android Animation: Making Your UI Designs Move 393


  1. Now you are ready to add the method calls off of the animImageView
    ImageView object, which will setup the source image plate using the
    .setImageResource( ) method call, clear out the background image plate
    using the .setBackground(null) method call, and start the animation using a
    .startAnimation( ) method call. This would be done in the third ImageButton
    event handling structure, using the following code, shown in Figure 10-36:


animImageView.setImageResource(R.drawable.anim_lightship);
animImageView.setBackground(null);
animImageView.startAnimation(lightShipAnim);

Figure 10-36. Add a Java statement to the imageButtonThree event handler setting image, background, and animation



  1. Now we are ready to test the animation using the Run As ➤ Android
    Application menu sequence, and as you can see in Figure 10-37, the
    energy-based lightship animation pulses and twinkles as expected. If you
    want to, use the PorterDuff class to blend the black parts of the image.
    The Android PorterDuff class is too advanced to cover in this book.

Free download pdf