284 CHAPTER 8: Android UI Design: Using Advanced ViewGroup Layout Containers
Notice that the green grid guidelines in the Graphical Layout Editor are not taking your columnSpan
parameter into consideration, as a grid line is still showing to the right of the AnalogClock, showing
both the left cell and the right cell. If the GLE was “rendering” the columnSpan attribute you added
correctly, there would not be a green vertical dotted line in the top row, because you’ve defined a
“span,” and that should show as one big cell!
So, as you can see, Eclipse ADT is not 100% perfect, and there are still some code improvements
for Google developers, as well as Eclipse ADT developers to implement, so that more and more of
the XML parameters are visualized correctly inside of the GLE.
Still, there are some useful features in the GLE, especially for working with the GridLayout class, as
you may have noticed from the dozen or so grid-related icons that are located above the preview
area in Figure 8-13.
The “take away” here is not to expect Eclipse, ADT, or the Android SDK to be bug-free and to work
perfectly; you have to work with what you have got with this development environment at any given
point in time. Over time, the IDE (Eclipse) and SDK (Android Developer Tools Plug-In and Android
SDK) will improve in both function and stability, as teams of people are working on these tools every
day, just as you are working on developing your Android apps every day!
Despite the incorrect grid-rendering guides, the AnalogClock is centering in the top of the
GridLayout correctly, so the android:columnSpan parameter has correctly spanned the top two
columns into one single column, and the android:layout_gravity="center" parameter is centering
the AnalogClock correctly within this single grid cell.
If you want to, you can toggle the grid guides icon back off and see that the design looks really
professional at this point in time. The only thing I can think of trying to improve this design is
right-aligning the EditText widgets!
Next, let’s use some more android:layout_gravity parameters, in the
align them with the Button UI widgets on the right instead of left-aligning the labels with the left side
of the display screen.
Align GridLayout Cells: Using the layout_gravity Parameter
You have already seen the android:layout_gravity parameter in action centering your AnalogClock
widget; let’s use it to right-align our EditText widgets with our Button widgets. The easiest way to do
this is to copy the UI parameter from the
and change it to use the right constant, instead of the center_horizontal constant, as you can see in
Figure 8-17.