A (175)

(Tuis.) #1

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


message. This is because Eclipse will then see the value as a String value and not a constant if it
contains any spaces! Essentially, this vertical bar ties the two constants together, so that they will be
considered to be one single constant value.


The GridLayout.Spec Nested Class: Horizontal and Vertical Spec


A GridLayout.Spec nested class hierarchy begins with the Java Object master class, and directly
creates this GridLayout.Spec nested class. Thus this class could be thought of as being “scratch
coded” to provide Spec object structures for the GridLayout class, which is why it is a nested
(helper) class. You could think of a Spec object as specifying or containing the “row and column
alignment structure.” These Spec objects are used at the very core of the Android GridLayout UI
class. A Spec object is used to define each of the horizontal or vertical attribute settings (parameters
or characteristics) for a given group of grid cells. The GridLayout.Spec Java class hierarchy can be
visualized as follows:


java.lang.Object



android.widget.GridLayout.Spec



The Android GridLayout.Spec class is a public static class, and it extends the java.lang.Object
superclass. This class provides the Spec object which is used to define the core row and column
definition and functionality for the GridLayout algorithm. This data is then used by the GridLayout
engine to create the scalable Grid Layout UI design.


Since this Spec object is used internally, inside of the GridLayout class, we will focus in this chapter
on your design of the GridLayout UI, and its parameters rather than get into the inner algorithm
workings of the class.


The GridLayout Class Parameters: Default Settings


The GridLayout algorithm has a dozen primary parameters which are utilized in its grid layout engine
algorithm, which is defined (using Java code) in the GridLayout class. These parameters (variables)
in the GridLayout class need to have their default settings in place (initially defined), in order for the
GridLayout algorithm to work correctly. This is done just in case developers, such as yourself, forget
to define any of these parameters and settings, by using XML parameters in your GridLayout UI
definition file.


These XML parameters should all be considered, and set, in your GridLayout UI design XML markup.
Just in case you forget any of these, the GridLayout class will define default values for them. These
default values are shown in Tables 8-4 and 8-5, and will be assigned in the case that any of these
settings are overlooked, or so that they can be left set to their default settings. This is why I’m going
over what these default values are in this section of the chapter. In this way, the GridLayout class
algorithm will “throw” no errors or exceptions, as it will always have default values.

Free download pdf