A (175)

(Tuis.) #1

494 CHAPTER 13: Android Service Class and Threads: Background Processing



  1. To create the second ImageView UI widget, copy and paste the XML
    mark-up for the first ImageView child tag underneath itself and change
    the playAudio ID to be a stopAudio ID. Create a reference to sound1 to
    reference a sound0 asset. Next, add an android:layout_alignParentTop
    as well as an android:layout_alignParentRight parameter and set both of
    these to a value of “true.” These will serve to force this audio off icon into the
    upper-right corner of your UI design. Everything else will remain the same, as
    shown in the following XML mark-up:


<ImageView android:id="@+id/stopAudio" android:src="@drawable/sound0"
android:contentDescription="@string/play_audio" android:padding="60dip"
android:layout_alignParentTop="true" android:layout_alignParentRight="true"
android:layout_marginLeft="-50dip" android:layout_marginTop="-50dip"
android:layout_width="wrap_content" android:layout_height="wrap_content" />

Since the widgets come after the widget, their compositing (layer)
z-order puts them on top of the digital video asset, so they will float above it. Since you are using a
PNG32 digital image asset, complete with an 8-bit anti-aliased alpha channel and 24-bit RGB image
data, you will get a perfectly seamless composite, complete with attractive icons made with 3D
software floating in the corners of your video screen!



  1. Now you are ready to open your PlayVideo.java Activity subclass and
    declare two ImageView objects at the top of the class, named soundOn
    and soundOff. Use the following line of Java code to do so, as shown in
    Figure 13-11:


ImageView soundOn, soundOff;

Figure 13-10. Add child tags for the playAudio and stopAudio icons and configure them with parameters

Free download pdf