CHAPTER 8: Android UI Design: Using Advanced ViewGroup Layout Containers 271
You are about to see how much more efficient a
parameters into the parent layout container tag, and zero parameters into the child UI widget tags,
we can achieve exactly the same result using far less XML markup.
You can even use the GridLayout parent tag with no parameters (except for the required layout_width
and layout_height), and with zero child tag parameters, to achieve a LinearLayout type of UI design!
Once you remove the 17 RelativeLayout parameters from your
markup, including the android:layout_margin parameter in the first child
would expect to again see all of your UI elements stacked on top of each other, in the upper-right
corner of the screen, when you use the Graphical Layout Editor (GLE) tab to preview your UI design.
However, as you can see in Figure 8-4, because you are using the
elements will actually be laid out in a horizontal grid, even with no parent tag or child tag (layout)
parameters being specified whatsoever. This means that it would be possible for you to create a
(horizontal) LinearLayout type of UI layout design in Android by using the GridLayout class with zero
parent or child UI layout parameters.
Figure 8-4. Using Graphical Layout Editor tab set in landscape mode to see how GridLayout aligns all UI widgets
There is a “layout orientation” toggle icon at the top of the Graphical Layout Editor preview
(rendering) pane which will make this more obvious to you, once you select landscape mode to
give you a wider view of what the GridLayout engine is doing with these (minimalist) parent tag
configuration parameters. The icon shows a smart phone with an “arcing arrow” on it, which signifies
flipping the UI layout design view between portrait (up and down, or a vertical screen orientation)
and landscape (widescreen, or a horizontal screen orientation) modes.
Click on this icon, shown outlined in red in Figure 8-4, to toggle the screen preview orientation back
and forth, or use the down-facing arrow to drop down a more detailed menu, allowing you to select
the toggle, or the mode, specifically. There are also UI Mode and Night Mode sub-menus from
which you can select GLE preview modes.