402 CHAPTER 11: Digital Video: Streaming Video, MediaPlayer, and MediaController classes
The most often used gravity constant with the FrameLayout container is fill, as one usually wants
content or UI elements, such as the VideoView, to be displayed “full screen.” Your second most
often used constant would be center, which is similar to fill, but does not scale the content; rather,
it centers the content or UI element (the child widget) in the display.There are also constants
provided to fill or center your UI widget or the nested UI layout container in only the horizontal
(X-axis) or the vertical (Y-axis) dimension. These would be the fill_vertical or fill_horizontal, and the
center_vertical or center_horizontal constants. These constants, shown in Table 11-1, will allow
you to fine-tune how Android will position your UI widget inside of your FrameLayout UI container.
It is important to note that using fill_vertical or fill_horizontal may change your content aspect ratio,
which may distort that content in an undesirable way.
Table 11-1. These android:layout_gravity Constants Are Defined by the Nested Class FrameLayout.LayoutParams
Gravity Constant The function which is specified by using this Gravity Constant
top Aligns UI element to or at the TOP of a FrameLayout container
bottom Aligns UI element to or at the BOTTOM of a FrameLayout container
left Aligns UI element to or at the LEFT of a FrameLayout container
right Aligns UI element to or at the RIGHT of a FrameLayout container
center_vertical Centers the UI element (or UI layout container) vertically
center_horizontal Centers the UI element (or UI layout container) horizontally
center Aligns UI element to or at the CENTER of a FrameLayout container
fill_vertical Scales UI element (or layout container) to fill Frame vertically
fill_horizontal Scale UI element (or layout container) to fill Frame horizontally
fill Scales UI element to FILL the FrameLayout container
clip_vertical Clips the top and bottom edges of the UI element for FrameLayout
clip_horizontal Clips the left and right edges of the UI element for FrameLayout
start Aligns UI element to or at the START of the FrameLayout container
end Aligns UI element to or at the END of the FrameLayout container
There are some more advanced constants, such as clip_horizontal and clip_vertical, which are
conceptually a bit more challenging, as these will “clip” (that is, remove a portion of) your UI element
or content, in either the horizontal (X-axis) or the vertical (Y-axis). In digital imaging, this operation
is termed “cropping,” and instead of scaling your content (or UI design) to fit any given screen
dimensions, these clipping constants will instead remove (clip away) parts of your content or
design, in order to make it fit the new screen size and dimensions.
Finally, you can use start and end constants to implement both RTL (Right To Left) and LTR (Left To
Right) “directional” UI layouts. These would replace your left and right constants (for LTR), or right
and left constants (for RTL). If you are developing for end users that use RTL languages, and you
need your UI designs to be able to mirror these types of RTL language design scenarios, use a start
and end constant instead of left and right.