Table Layout
Android TableLayout groups views into rows and columns. You will use the <TableRow> element to build a row in the table. Each row has zero or more cells; each cell can hold one View object.
TableLayout containers do not display border lines for their rows, columns, or cells.
Important Attributes for the Table Layout:
Attribute
|
Description
|
android:id
|
This
is the ID which uniquely identifies the layout.
|
android:collapseColumns
|
This specifies the
zero-based index of the columns to collapse. The column indices must be separated
by a comma: 1,2,5
|
android:stretchColumns
|
The
zero-based index of the columns to stretch. The column indices must be separated
by comma: 1,2,5
|
android:shrinkColumns
|
The zero-based index
of the columns to shrink. The column indices must be separated by comma: 1,2,5
|
For example, following is the content of activity_main.xml containing Table Layout:
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:shrinkColumns="*"
android:stretchColumns="*" >
<TableRow
android:id="@+id/tableRow2"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textView11"
android:layout_width="0dp"
android:layout_weight="1"
android:gravity="center"
android:text="col 1" />
<TextView
android:id="@+id/textView12"
android:layout_width="0dp"
android:layout_weight="1"
android:gravity="center"
android:text="col 2" />
<TextView
android:id="@+id/textView13"
android:layout_width="0dp"
android:layout_weight="1"
android:gravity="center"
android:text="col 3" />
<TextView
android:id="@+id/textView14"
android:layout_width="0dp"
android:layout_weight="1"
android:gravity="center"
android:text="col 4" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:focusable="false"
android:gravity="center_horizontal"
android:measureWithLargestChild="false" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_span="4"
android:background="#b0b0b0"
android:padding="18dip"
android:text="@string/row_1"
android:textColor="#000"
android:textSize="18sp" />
</TableRow>
<TableRow
android:id="@+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/TextView04"
android:layout_weight="1"
android:background="#dcdcdc"
android:gravity="center"
android:padding="20dip"
android:text="Row 2 column 1"
android:textColor="#000000" />
<TextView
android:id="@+id/TextView04"
android:layout_weight="1"
android:background="#d3d3d3"
android:gravity="center"
android:padding="20dip"
android:text="Row 2 column 2"
android:textColor="#000000" />
<TextView
android:id="@+id/TextView04"
android:layout_weight="1"
android:background="#cac9c9"
android:gravity="center"
android:padding="20dip"
android:text="Row 2 column 3"
android:textColor="#000000" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<TextView
android:id="@+id/TextView04"
android:layout_weight="1"
android:background="#cac9c9"
android:gravity="center"
android:padding="18dip"
android:text="Row 3 column 1"
android:textColor="#000000" />
<TextView
android:id="@+id/TextView04"
android:layout_weight="1"
android:background="#a09f9f"
android:gravity="center"
android:padding="18dip"
android:text="Row 3 column 2"
android:textColor="#000000" />
</TableRow>
</TableLayout>
Output
Comments
Post a Comment