Home  >  Article  >  Backend Development  >  Android UI control series: TableLayout (table layout)

Android UI control series: TableLayout (table layout)

黄舟
黄舟Original
2017-01-19 10:04:091359browse

TableLayout is a view group that displays views in rows and columns

1. Start a new project named HelloTableLayout

2. Open the res/layout/main.xml file And insert the following content

<?xml version="1.0" encoding="utf-8"?>
<TableLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:stretchColumns="1">
        <TableRow>
                <TextView
                        android:layout_column="1"
                        android:text="Open..."
                        android:padding="3dip"
                />
                <TextView
                        android:text="Ctrl-O"
                        android:gravity="right"
                        android:padding="3dip"
                />
        </TableRow>
        <TableRow>
                <TextView
                        android:layout_column="1"
                        android:text="Save..."
                        android:padding="3dip"
                />
                <TextView
                        android:text="Ctrl-S"
                        android:gravity="right"
                        android:padding="3dip"
                />
        </TableRow>
        <TableRow>
                <TextView
                        android:layout_column="1"
                        android:text="Save as..."
                        android:padding="3dip"
                />
                <TextView
                        android:text="Ctrl-Shift-S"
                        android:gravity="right"
                        android:padding="3dip"
                />
        </TableRow>
        <View
                android:layout_height="2dip"
                android:background="#FF909090"
        />
        <TableRow>
                <TextView
                        android:text="X"
                        android:padding="3dip"
                />
                <TextView
                        android:text="Import..."
                        android:padding="3dip"
                />
        </TableRow>
        <TableRow>
                <TextView
                        android:text="X"
                        android:padding="3dip"
                />
                <TextView
                        android:text="Export..."
                        android:padding="3dip"
                />
                <TextView
                        android:text="Ctrl-E"
                        android:gravity="right"
                        android:padding="3dip"
                />
        </TableRow>
        <View
                android:layout_height="2dip"
                android:background="#FF909090"
        />
        <TableRow>
                <TextView
                        android:layout_column="1"
                        android:text="Quit"
                        android:padding="3dip"
                />
        </TableRow>
</TableLayout>

Notice that this file is similar to the structure of the table in HTML. The TableLayout element is like the

element in HTML; the TableRow is like a element; But for each cell, you can use various view elements. In this example, each cell uses TextView. Between these rows, there is also a basic View for drawing horizontal lines

TextView Some attributes in

android:layout_column="1": Indicates that the control is placed on the column numbered 1, and the number starts from 0

android:gravity="right": Definition The font is displayed on the right in the parent control

android:stretchColumns="1": Set which columns to automatically stretch. The column ID starts from 0. If there are multiple columns, use "," to separate them. The function here is to allow the second column to expand to all available space

android:shrinkColumns: Set which columns to automatically shrink. The column ID starts from 0. If there are multiple columns, use "," to separate them

android:collapseColumns: Set which columns to automatically hide. The column ID starts from 0. If there are multiple columns, use "," to separate them

By the way: android:layout_span indicates how many columns of space a control occupies

The following is the basic View, which is to draw a horizontal line 2dip high on the screen

<View
android:layout_height=”2dip”
android:background=”#FF909090″
/>

3. The running results are as follows:

Android UI control series: TableLayout (table layout)

The above is the content of the Android UI control series: TableLayout (table layout). For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn