A (175)

(Tuis.) #1
CHAPTER 11: Digital Video: Streaming Video, MediaPlayer, and MediaController classes 403

These RTL (Right To Left) and LTR (Left To Right) layout constants were only recently added, in
Android 4.2, to allow design support for languages which are read starting on the right side of the
screen and moving toward the left side of the screen. Android will automatically reverse the value of
the start and end constants, depending on whether a RTL or LTR screen direction is being used by
the user (that is, depending on the language setting).


The gravity constants would only be used in a FrameLayout when there is more than one child
widget (multiple UI widgets, or nested ViewGroup layout containers). This is similar to the way
you will use the top, bottom, left, or right constants to “pin” UI widgets or layout containers to the
sides of a FrameLayout (display) like you did with the GridLayout. Gravity is used for generalized
positioning, not for precise positioning, like the parameters that you find in the RelativeLayout class,
for instance, which can provide designs that are precise and at the same time are also scalable to
different screen sizes and shapes.


Creating a Frame Layout Using XML Mark-Up


The first thing that we will need to do to add the “Fly Over Planet” video playback menu option to
your app is to add a constant, as shown in Figure 11-1, which you will use later to label
your second menu item.


Figure 11-1. Add a constant resource named play_video and give it a data value of “Fly Over Planet”



  1. Name the constant play_video and give it a String data value of
    Fly Over Planet using the following markup:


<string name="play_video">Fly Over Planet</string>


  1. Next, right-click the main.xml file in the /res/menu folder and Open it.

  2. Copy and paste the first child tag underneath itself and change
    edit_galaxy to play_video and 100 to 200.

  3. Change the action_settings to 300 , as is shown in Figure 11-2, so that
    your parent tag now contains three MenuItem objects. Once you
    complete the XML menu definition file upgrade, you’ll be ready to go into the
    Java code and access play_video.

Free download pdf