A (175)

(Tuis.) #1

264 CHAPTER 8: Android UI Design: Using Advanced ViewGroup Layout Containers


The GridLayout.LayoutParams class contains four static XML parameters shown in Table 8-1.
These include: android:layout_column, android:layout_row, android:layout_columnSpan, and
android:layout_rowSpan. There is also one dynamic Java method, .setGravity(), which can also be
set or configured statically, using the GridLayout XML definition file, by using the android:layout_gravity
XML parameter that I discussed earlier.


This is clearly a small number of configuration options for what is considered to be a complex
and powerful UI layout container class. The reason I split these 12 GridLayout parameter options
between the 5 that go inside the child UI widget tags, and the 7 which control how the GridLayout
algorithm (I like to call it the GridLayout “engine”), is to point out how differently this particular UI
layout container works from the other UI layout container classes!


The other seven XML parameters shown in Table 8-2 are used for setting how the GridLayout class’s
algorithm (engine) is going to interpret a given GridLayout definition. These therefore specify what I
would term “global” GridLayout setting values, which will be used to configure this “grid alignment
engine” which the GridLayout class creates for you. These global GridLayout parent parameters are
included in this section so that we can keep these XML GridLayout parameters all together in one
section (and one discussion). There are also two other nested classes, which deal with GridLayout
XML parameters, which we will cover during the next two sections of this chapter.


Table 8-2. GridLayout Parent Layout Container “Configuration” Parameters, Along with Their Primary Functionality

GridLayout Parent Parameter GridLayout Parent Parameter Function Description:

android:columnCount A Max. Column Count to use when auto-positioning Views
android:rowCount A Maximum Row Count to use when auto-positioning Views
android:useDefaultMargins Uses auto-margin algorithm when no margins specified
android:alignmentMode Sets how to align the grid, relative to View’s margins
android:columnOrderPreserved Force column boundaries to be in same order as indices
android:rowOrderPreserved Force row boundaries to be in same order as indices
android:orientation Sets orientation for grid (unused in layout algorithm)

The most often used parent attributes are the android:layoutrowCount and android:layout
columnCount parameters. These important parameters will allow you to define your GridLayout
in a static (or fixed) fashion, which is more memory-efficient, because a fixed memory area can
be established and optimized “up-front” for the grid UI layout. This is how we will be defining our
GridLayout UI design during this chapter.


There are three “flag” (Boolean values, set to true or false) parameters, which can be utilized for
turning on or off grid cell margins (the android:layout_useDefaultMargins parameter), preserving
row order (the android:layout_rowOrderPreserved parameter), and for preserving column order
(the android:layout_columnOrderPreserved parameter).


There are two constant parameters, which are used in conjunction with Android OS constants for
specifying the GridLayout alignment mode (the android:layout_alignmentMode parameter) and the
GridLayout’s orientation (the android:layout_orientation parameter).

Free download pdf