collapseColumns  设置需要被隐藏的列序号(序号从0开始)

shrinkColumns     设置允许被首夺的列的序号(序号从0开始

stretchColumns    设置允许被拉伸的列的序号(序号从0开始

原先没设置时候的样子

Table中collapseColumns,stretchColumns


设置后的效果:

Table中collapseColumns,stretchColumns


<LinearLayout xmlns:andro
    android:
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="第一个tabelLayout"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <!-- 第二列允许收缩,第三列允许拉伸 -->
    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" 
        <strong><span style="color:#ff0000;">android:shrinkColumns="1" //收缩
        android:stretchColumns="2">//拉伸</span></strong>

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

        <TableRow
            android:
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

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

            <Button
                android:
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="收缩的第二列,看出效果了么" />

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

        </TableRow>
    </TableLayout>
    
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="第二个tabelLayout"
        android:textAppearance="?android:attr/textAppearanceLarge" />
    
    <!-- 第二列隐藏 -->
    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" 
        <strong><span style="color:#ff0000;">android:collapseColumns="1">//隐藏</span></strong>

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

        <TableRow
            android:
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

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

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

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

        </TableRow>
    </TableLayout>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="第三个tabelLayout"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <!-- 第二列和第三列拉伸 -->
    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" 
       <strong><span style="color:#ff0000;"> android:stretchColumns="1,2">//拉伸</span></strong>

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

        <TableRow
            android:
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

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

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

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

        </TableRow>

        <TableRow
            android:
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

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

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

        </TableRow>
    </TableLayout>

</LinearLayout>


相关文章:

  • 2022-12-23
  • 2021-07-10
  • 2022-12-23
  • 2022-12-23
  • 2021-07-14
  • 2021-11-07
  • 2021-07-13
  • 2022-03-03
猜你喜欢
  • 2021-10-28
  • 2022-12-23
  • 2021-09-06
  • 2021-12-02
  • 2021-06-22
  • 2022-12-23
  • 2021-10-31
相关资源
相似解决方案