CHAPTER 8: Android UI Design: Using Advanced ViewGroup Layout Containers 263
If no alignment characteristics are specified, then the GridLayout class will consider that child UI
widget to be fixed, and thus to be inflexible. Fixed versus flexible grid cells are a consideration
in how the GridLayout will scale or “morph” between different screen sizes and shapes; that is,
between the different Android device types.
If you have multiple UI widgets inside of the same row or column grouping, the UI widgets will
be considered to be acting together (that is, in parallel with each other). These groupings will be
considered to be flexible, but only if all of the child UI widgets inside of the grouping are also
configured to be, or deemed to be, flexible.
For example, if you wanted to make one of your GridLayout columns scale dynamically (to be
stretchable), you would simply make sure that you define the android:layout_gravity parameter inside
of each of your UI widgets which are contained within that particular GridLayout column. On the
other hand, if you wanted to prevent any of your GridLayout UI columns from stretching, or in other
words, make them fixed, or static, you would need to ensure that one of your UI widgets in that
column does not define a setting for this android:layout_gravity parameter.
When a layout_gravity parameter-specified principle of grid flexibility is defined in a way that is
interpreted by the GridLayout algorithm as being ambiguous (that is, able to be interpreted in more
than one unique way), the GridLayout class’s algorithm will prioritize flexibility for rows and columns
which are closer to the right and bottom sides of your UI design. This would be the “end” of the UI
design, since it starts in the upper-left corner, at pixel location 0,0.
The GridLayout.LayoutParams Nested Class: Parameters
The GridLayout.LayoutParams class hierarchy begins with the Java Object master class, and
progresses from the ViewGroup.LayoutParams class to the ViewGroup.MarginLayoutParams
class, and finally down to the GridLayout.LayoutParams class. A class inheritance hierarchy would
be structured in the following fashion:
java.lang.Object
android.view.ViewGroup.LayoutParams
android.view.ViewGroup.MarginLayoutParams
android.widget.GridLayout.LayoutParams
This class provides parameters and constants which will be used in your GridLayout XML UI
definition file, in order to create your GridLayout UI designs. We will go over these five GridLayout
parameters here, as seen in Table 8-1, and we will utilize many of them in our GridLayout UI, which
we will be creating during the chapter.
Table 8-1. Five GridLayout Attributes (Parameters) Along with Their Primary Functions (Used in Child UI Widgets)
GridLayout Parameter Parameter Function Description
layout_column Column boundary indicating left group of cells occupied
layout_row Row boundary indicating top group of cells occupied
layout_gravity Gravity specifying how UI widgets are to be placed in a cell
layout_columnSpan Difference between left or right boundary delimiting cell span
layout_rowSpan Difference between top or bottom boundary delimiting cell span