1. 程式人生 > 其它 >【Android】TableLayout子View拉伸教程

【Android】TableLayout子View拉伸教程

stretchColumns表示拉伸某一列的寬度,用型號*表示拉伸全部。

layout_span表示該控制元件佔多少列,如果不需要自適應寬度而是固定他的寬度,則把寬度設為0dp即可


<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:stretchColumns="*">

    <TableRow>


        <Button
            android:layout_height="200dp"
            android:layout_span="1" />

        <TableLayout

            android:layout_span="1">

            <Button
                android:layout_height="50dp"
                android:text="123123123123123123123123123" />

            <Button android:layout_height="50dp" />

            <Button android:layout_height="50dp" />

            <Button android:layout_height="50dp" />
        </TableLayout>
    </TableRow>
</TableLayout>

拉伸並且平均寬度:

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:stretchColumns="*">
    <TableRow>
        <Button
            android:text="233"
            android:layout_width="0dp"
            android:layout_height="200dp"
            android:layout_span="1" />
        <TableLayout
            android:layout_width="0dp"
            android:layout_span="1">
            <Button
                android:layout_height="100dp"
                android:text="123123123123123123123123123" />
            <Button
                android:layout_height="100dp"
                android:text="666" />
        </TableLayout>
    </TableRow>
</TableLayout>