======GridLayout======

<android.support.v7.widget.GridLayout
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:columnCount="4"
        app:orientation="horizontal"
        app:rowCount="5" >

        <Button
            android:id="@+id/one"
            android:text="1" />

        <Button
            android:id="@+id/two"
            android:text="2" />


        <Button
            android:id="@+id/three"
            android:text="3" />

        <Button
            android:id="@+id/devide"
            android:text="/" />

        <Button
            android:id="@+id/four"
            android:text="4" />

        <Button
            android:id="@+id/five"
            android:text="5" />

        <Button
            android:id="@+id/six"
            android:text="6" />

        <Button
            android:id="@+id/multiply"
            android:text="×" />

        <Button
            android:id="@+id/seven"
            android:text="7" />

        <Button
            android:id="@+id/eight"
            android:text="8" />

        <Button
            android:id="@+id/nine"
            android:text="9" />

        <Button
            android:id="@+id/minus"
            android:text="-" />

        <Button
            android:id="@+id/zero"
            app:layout_columnSpan="2"
            app:layout_gravity="fill"
            android:text="0" />

        <Button
            android:id="@+id/point"
            android:text="." />

        <Button
            android:id="@+id/plus"
            app:layout_gravity="fill"
            app:layout_rowSpan="2"
            android:text="+" />

        <Button
            android:id="@+id/equal"
            app:layout_columnSpan="3"
            app:layout_gravity="fill"
            android:text="=" />
    </android.support.v7.widget.GridLayout>

记录下GridLayout与TableLayout布局的一些知识点,这两个布局对比起来弄,感觉明显比较更能加深印象。

GridLayout的使用设置:

GridLayout 布局在 Level14才被支持,之前版本要使用的话,要按以下步骤设置:

 1. import -> Existing Android Code Into Workspace  
 2. 选择目录: 在sdk下的GridLayout目录   
sdk\extras\android\support\v7\gridlayout 
 3. 勾选"Copy projects into workspace" 
TableLayout 的一些不足:  
至于有了TableLayout又搞个GridLayout的原因,简单试了下TableLayout,我认为至少有下面两个原因 
1.不能同时向水平和垂直方向做控件的对齐 
TableLayout继承了LinearLayout,因此只能向一个方向做控件的对齐。 
2.不能跨行跨列 
  因为TableLayout,不明确指定包含多少行,多少列,而是通过向TableRow里面添加其他组件,每添加一个组件该表格就增加一列。 
如果向TableLayout里面添加组件,那么该组件就直接占用一行。所以这种方式造成控件不能跨行跨列。 
而GridLayout,则用columnCount设置列数后,增加的控件在超过列数后自动换行进行排列。 
简单汇总下TableLayout的特点:  
Shrinkable : 该列的宽度可以进行收缩,以使表格能够适应父容器的大小 
Stretchable : 该列可以进行拉伸,以填满表格中空闲的空间 
Collapsed : 该列将会被隐藏 
GridLayout的特点:  
android:layout_row :  固定显示在第几行。 
android:layout_column :  固定显示在第几列,前面几列没控件的话就空着。 
android:layout_rowSpan : 跨几行 

android:layout_columnSpan:  跨几列  

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


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


        <Button
            android:id="@+id/btn01"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="独自一行" >
        </Button>


        <TableRow>


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


            <Button
                android:id="@+id/btn03"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="允许被收缩允许被收缩允许被收缩允许被收缩=====================萍萍萍萍萍萍萍萍萍萍萍萍萍萍" >
            </Button>


            <Button
                android:id="@+id/btn04"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="允许被拉伸" >
            </Button>
        </TableRow>
    </TableLayout>
    <!-- 定义第2个表格,指定第2列隐藏 -->


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


        <TableRow>


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


            <Button
                android:id="@+id/btn06"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="被隐藏列" >
            </Button>


            <Button
                android:id="@+id/btn07"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="允许被拉伸" >
            </Button>
        </TableRow>
    </TableLayout>
    <!-- 定义第3个表格,指定第2列填满空白 -->


    <TableLayout
        android:id="@+id/tablelayout03"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:stretchColumns="1" >


        <TableRow>


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


            <Button
                android:id="@+id/btn09"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="填满剩余空白" >
            </Button>
        </TableRow>
    </TableLayout>
    <!-- 定义第3个表格,指定第2列横跨2列 -->


    <TableLayout
        android:id="@+id/tablelayout04"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >


        <TableRow>


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


            <Button
                android:id="@+id/btn11"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_column="2"
                android:text="填满剩余空白" >
            </Button>
        </TableRow>
    </TableLayout>





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值