<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <!-- 定义第一个表格布局,指定第2列允许收缩,第3列允许拉伸 -->

    <TableLayout
        android:id="@+id/TableLayout01"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:shrinkColumns="1"
        android:stretchColumns="2" >

        <!-- 直接添加按钮,它自己会占一行 -->

        <Button
            android:id="@+id/ok1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="独自一行的按钮" />
        <!-- 添加一个表格行 -->

        <TableRow>

            <!-- 为该表格行添加3个按钮 -->

            <Button
                android:id="@+id/ok2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="普通按钮" />

            <Button
                android:id="@+id/ok3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="收缩的按钮" />

            <Button
                android:id="@+id/ok4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="拉伸的按钮" />
        </TableRow>
    </TableLayout>

    

</LinearLayout>

上述LinearLayout中只有一个TableLayout,在<TableLayout处有警告信息:This TableLayout layout or its LinearLayout parent is possibly useless

 

下面的LinearLayout中有两个TableLayout就没有这种警告信息:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <!-- 定义第一个表格布局,指定第2列允许收缩,第3列允许拉伸 -->

    <TableLayout
        android:id="@+id/TableLayout01"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:shrinkColumns="1"
        android:stretchColumns="2" >

        <!-- 直接添加按钮,它自己会占一行 -->

        <Button
            android:id="@+id/ok1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="独自一行的按钮" />
        <!-- 添加一个表格行 -->

        <TableRow>

            <!-- 为该表格行添加3个按钮 -->

            <Button
                android:id="@+id/ok2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="普通按钮" />

            <Button
                android:id="@+id/ok3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="收缩的按钮" />

            <Button
                android:id="@+id/ok4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="拉伸的按钮" />
        </TableRow>
    </TableLayout>

    <TableLayout
        android:id="@+id/TableLayout02"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:collapseColumns="1" >

        <!-- 直接添加按钮,它自己会占一行 -->

        <Button
            android:id="@+id/ok5"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text=" 独自一行的按钮 " />
        <!-- 定义一个表格行 -->

        <TableRow>

            <!-- 为该表格行添加3个按钮 -->

            <Button
                android:id="@+id/ok6"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="普通按钮1" />

            <Button
                android:id="@+id/ok7"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="被隐藏的按钮" />

            <Button
                android:id="@+id/ok8"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="普通按钮 3" />
        </TableRow>
    </TableLayout>

</LinearLayout>

 

相关文章:

  • 2021-08-01
  • 2022-12-23
  • 2021-07-16
  • 2022-01-05
  • 2022-12-23
  • 2022-12-23
  • 2021-04-30
  • 2021-04-17
猜你喜欢
  • 2022-12-23
  • 2022-01-10
  • 2022-12-23
  • 2021-07-01
  • 2021-12-29
  • 2022-01-03
  • 2022-12-23
相关资源
相似解决方案