Android 表格布局TableLayout

<?xml version="1.0" encoding="utf-8"?>
<TableLayout android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:collapseColumns="0"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <Button android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:text="按钮1"

        >

    </Button>
    <TableRow>
        <Button android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:text="按钮2"

            >

        </Button>
        <Button android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:text="按钮3"

            >

        </Button>
        <Button android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:text="按钮4"

            >

        </Button>
        <Button android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:text="按钮5"

            >

        </Button>
        <Button android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:text="按钮6"

            >

        </Button>
    </TableRow>>
</TableLayout>

注意

android:collapseColumns="0"效果为隐藏,下标从0开始。

下面介绍项目中常见的一种:

当有一些空余的位置的时候,没有什么东西,可以通过控件来占位,当有新的内容占据的时候,所有的空的位置都会被挤出来。可以看看下面的例子:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <TableRow>
        <TextView android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            ></TextView>
        <ImageView android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:src="@drawable/hhh">
    </TableRow>
    <TableRow>
        <TextView android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            ></TextView>
        <TextView android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            ></TextView>
        <ImageView android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:src="@drawable/hhh">
    </TableRow>
    <TableRow>
        <TextView android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            ></TextView>
        <TextView android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            ></TextView>
        <TextView android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            ></TextView>
        <ImageView android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:src="@drawable/hhh">
        <ImageView android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:src="@drawable/hhh">
    </TableRow>
    <TableRow>
        <Button android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Go">
        </Button>>
    </TableRow>
</TableLayout>

猜你喜欢

转载自blog.csdn.net/a15929748502/article/details/110734021