A (175)

(Tuis.) #1

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


It is important, not only for experimentation and learning, but also for memory optimization (using
the smallest amount of memory needed to achieve your intended UI design result) to only use
the configuration parameters which are needed to achieve the result you desire; in this case, that
happens to be replicating the RelativeLayout UI design with a GridLayout UI design. Since we
are getting pretty close here, I wanted to try implementing the UseDefaultMargins configuration
parameter next, to see if this global parameter gives us a better UI alignment result than putting
dozens of layout_margin tags in the eight UI elements inside of the GridLayout currently. If it does
improve our layout visually, and give us a more professional end result, we will leave it in the UI design.


After we ascertain if the android:useDefaultMargins parameter is going to improve our GridLayout
UI design, we will start experimenting with changing the UI widget order inside of the parent layout
container, and learn about some of the other parameters which are important to know about relative
to creating a GridLayout design.


GridLayout Alignment: The UseDefaultMargins Constant


Add a new line in your parent tag after the required layout_width and layout_height
and add in the android:useDefaultMargins parameter set to a boolean value of true to turn on this
auto-alignment feature. The global alignment parameter is shown highlighted in Figure 8-7 along
with seven other parameters.


Figure 8-6. Use the GLE to show the GridLayout parent parameters and the Show Structure icon to show guides

Free download pdf