A (175)

(Tuis.) #1
CHAPTER 8: Android UI Design: Using Advanced ViewGroup Layout Containers 265

The GridLayout.Alignment Nested Class: Alignment Constants


The GridLayout.Alignment nested class hierarchy begins at the Java Object master class, and
directly creates this GridLayout.Alignment nested class, which you can think of as containing the
“alignment constants” for this GridLayout class, because that is what it does. This nested class
therefore uses the following Java class hierarchy:


java.lang.Object



android.widget.GridLayout.Alignment



The Android GridLayout.Alignment nested class is a public static abstract class, extending the
java.lang.Object superclass. This class provides the nine grid row and column alignment constants
which you will be using to set the GridLayout rowSpec and columnSpec parameters that hold your
grid definition settings for the child UI widgets contained in the grid layout.


The rowSpec and columnSpec parameters are actually objects, which are used to define the
GridLayout overall layout algorithm functionality for the GridLayout design. These are defined
internally to the GridLayout, using the GridLayout.Spec nested class, which we will be taking a look
at briefly in the next section of this chapter.


These nine rowSpec and columnSpec alignment constants are shown in Table 8-3. It is important to
note that you can use (define) one or more of the constants for each direction or axis, X and Y, for a
GridLayout UI design.


Table 8-3. GridLayout Parent Container Alignment Attributes or Parameters, Along with Primary Functionality

Alignment Constants: Alignment Constant Function Description:

TOP Align the Top Edge of the View with Top Edge of other Views
BOTTOM Align Bottom Edge of View with Bottom Edge of other Views
LEFT Align the Left Edge of View with Left Edge of other Views
RIGHT Align the Right Edge of View with Right Edge of other Views
START Align the Start Edge of View with Start Edge of other Views
END Align the End Edge of View with the End Edge of other Views
CENTER Center all of the Views contained within a given cell group
FILL View should be expanded to fill the entire cell group area
BASELINE Views in cell group (rows only) should be baseline aligned

This alignment constant specifies how your UI widgets should be placed within the cell grouping,
or how they should be scaled (resized) to fit the cell. Each X and Y alignment constant operates
independently of the other constant. As I mentioned before, you can also combine these together,
by using a vertical bar, like so: TOP|LEFT. Make sure not to use a space character between
these constants and the vertical bar, because if you do, you will get a “String Not Allowed” error

Free download pdf