A (175)

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

Now you are ready to use the Graphical Layout Editor tab to “render” or preview the new GridLayout
and child widget order, which as you can see in Figure 8 -1 0 is not what we are looking to achieve. The
EditText widget UI elements are placed into the grid layout first and the Button widget UI elements are
placed into the grid layout after that, which is probably what you were expecting to happen.


Figure 8-10. The different UI element arrangement in the GridLayout, and grid alignment icons at top-left


The question is, is there a simple (single) global parameter you can place in the parent
container, which will change the grid widget distribution (placement) algorithm, from placing
UI widgets from left to right, going in a top to bottom direction, which is what was happening
before, to using a different grid widget distribution (placement) algorithm, which would place the
same UI widgets from top to bottom, going in a left to right direction?


In fact, there is such a global parameter, called android:orientation, which is supported with the
GridLayout engine, just like it is with the parent (and child) tag. This makes these
two UI layout container classes even more similar, because, as you now know, these two UI layout
containers also share the layout weight parameter as well.


It is important to note that even though these two UI layout container (ViewGroup) classes are quite
similar, the GridLayout class is not in fact subclassed from the LinearLayout class. This would be the
assumption that one might make, due to the similarity between the two classes, as far as parameters
(and visual results with no parameter specified) are concerned.


The GridLayout uses the default android:orientation value of horizontal, which is shown in
Figure 8-10 as being set using the (selected) icon with the three columns on it, shown at the top-left
of the preview area in the GLE (Graphical Layout Editor).

Free download pdf