tags. The TableRow object will define a row that will contain its
own child widgets, again just like HTML.
Like the GridLayout container, the TableLayout container does not display border lines for its
rows or columns. Each row has zero (which is one in programmer numbering) or more cells. Each
cell will hold one View object. The number of columns that a TableLayout will have is defined by
the row that has the most cells (columns). You can leave cells empty in a TableLayout if you like.
TableLayout cells can span more than one column, just like they can in HTML. A width of a column
is defined using the row with the widest cell.
A TableLayout can specify individual columns as shrinkable or stretchable using a
.setColumnShrinkable( ) or .setColumnStretchable( ) method call. If it is earmarked as shrinkable,
a column width can be shrunk to fit the table into its parent container. If it is earmarked as stretchable,
it can expand its width to fit all extra space. The total width of a TableLayout will be defined by the
parent container, which in this case is the ContactGalaxy activity’s screen. Columns can be defined
to be both shrinkable and stretchable. If you do this, the column changes size to always use any
available space. You can also collapse (hide) a column by calling a .setColumnCollapsed( ) method.
Child widgets in a TableLayout may not specify a layout_width attribute. Width defaults to the
match_parent constant. A layout_height attribute may be defined by child widgets; the default
value will be wrap_content. If the child object is defined as a TableRow object, the height must be
set to be wrap_content. Cells are added to rows using an increasing column order, both in Java
code and XML. Column numbering is zero-based. If you do not specify column numbers for the child
cells, they will be auto-incremented by the TableLayout engine (algorithm).
If you skip any column number, it will be considered to be an empty cell in that row. Although
the typical child of a TableLayout is a TableRow, you can use a View subclass directly (without
wrapping it in a TableRow) as a child widget in your TableLayout UI. A View will be displayed as a
single row that spans all the table columns. Now you have the knowledge to be able to complete the
inside of your TableLayout UI design in the next section.
Creating Your TableLayout UI for ContactGalaxy
First, create five constants in your strings.xml file in the /res/values folder to serve as
your Button UI element labels, as shown in Figure 14-19. These will list all of the galaxy rulers, add
Viceroys for each galaxy, and return the user to the Home Galaxy (application home screen or the
MainActivity class).