• Android布局管理器(表格布局)


    表格布局有TableLayout所代表,TableLayout继承了LinearLayout,因此他的本质依然是LinearLayout。

    表格布局采用行、列的形式来进行管理,在使用的时候不需要声明多少行、多少列,而是通过添加TableRow、其他组件来控制表格的行数和列数。

    每次向TableLayout添加一个TableRow,该TableRow就是一个表格行,同时TableRow也是容器,可以在其中不断的添加其他的组件,每添加一个子组件,该表格的列就增加一列

    在表格布局管理器中,可以为单元格设置如下三种行为方式

    1. Shrinkable:如果某一列被设置为Shrinkable,那么该列的所有单元格的宽度可以被收缩,以保证该表格能适应父容器的宽度
    2. Stretchable:如果某一列被设置为Stretchable,那么该列的所有单元格的宽度可以被拉伸,以保证组件能全部填满表格空余控件
    3. Collapsed:如果某个列被设置为该属性,那么该列的所有单元格都会被隐藏

    因为TableLayout继承了LinearLayout类,因此除了支持LinearLayout的全部属性外还支持下面的三个属性

    XML属性

    方法

    说明

    android:collapseColumns

    setColumnCollapsed(int,boolean)

    设置需要被隐藏的列的序号,多个使用都逗号隔开

    android:shrinkColumns

    setShrinkAllColumns(boolean)

    设置允许被收缩的列的序号,多个使用逗号隔开

    android:stretchColumns

    setStretchAllColumns(boolean)

    设置允许被拉伸的列的序号,多个使用逗号隔开

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        tools:context="com.example.tablelayout.MainActivity" >
    
       
        <!-- 第一个TableLayout,指定二列允许收缩,三列允许拉伸 -->
        <TableLayout 
            android:id="@+id/tableLayout_one"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:shrinkColumns="1"
            android:stretchColumns="3">
            
            <Button 
                android:id="@+id/ok1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="独自一行的按钮"/>
            <TableRow>
                <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,指定二列允隐藏-->
        <TableLayout 
            android:id="@+id/tableLayout_two"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:collapseColumns="2">
            
            <Button 
                android:id="@+id/ok5"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="独自一行的按钮"/>
            <TableRow>
                <Button 
                    android:id="@+id/ok6"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="普通按钮"/>
                <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="隐藏按钮"/>
           </TableRow>  
        </TableLayout>
        
        <!-- 第三个TableLayout,指定二列允许拉伸,三列允许拉伸 -->
        <TableLayout 
            android:id="@+id/tableLayout_three"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:shrinkColumns="1,2">
            
            <Button 
                android:id="@+id/ok9"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="独自一行的按钮"/>
            <TableRow>
                <Button 
                    android:id="@+id/ok10"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="普通按钮"/>
                <Button 
                    android:id="@+id/ok11"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="拉伸按钮"/>
                <Button 
                    android:id="@+id/ok12"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="拉伸按钮"/>
           </TableRow>
        </TableLayout>
    </LinearLayout>

  • 相关阅读:
    URL
    VI,CI,UI
    ubuntu优化使用
    Django入门之自定义页面
    python3 连接SQLserver
    Python3 捕捉异常
    python3 异常处理
    Django入门
    较大型站立会议(交付前两天)--张永组-2014-04-15
    站立会议-2014-04-14
  • 原文地址:https://www.cnblogs.com/qadada/p/4468091.html
Copyright © 2020-2023  润新知