Android4.0新增布局GridLayout(网格布局)

网格布局由GridLayout代表,它是Android4.0新增的布局管理器,因此需要在Android4.0之后的版本中才能使用该布局管理器。

如果希望在更早的Android平台上使用该布局管理器,则需要导入相应的支撑库。

GridLayout的作用类似于HTML中的table标签,它把整个容器划分成rows*columns个网格,每个网格可以放置一个组件。除此

之外,也可以设置一个组件横跨多少列、一个组件纵跨多少行。

GridLayout提供了setRowCount(int)和setColumnCount(int)方法来控制该网格的行数量和列数量:

下面来看一下具体的使用案例:先看效果截图:

xml的相应代码如下:

<GridLayout
  
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:rowCount="6"
    android:columnCount="4"
   
    >
    <EditText 
        android:id="@+id/edittext"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_columnSpan="4"
        android:layout_row="0"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:padding="10dp"
        />
    <Button 
        android:id="@+id/clear"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_columnSpan="4"
       android:layout_row="0"
        android:text="清除"
         android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:padding="10dp"
        />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_row="3"
        android:layout_column="0"
          android:layout_marginLeft="5dp"
        android:text="9" 
        android:padding="10dp"
        />
     <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_row="3"
        android:layout_column="1"
          android:layout_marginLeft="5dp"
        android:text="9" 
        android:padding="10dp"
        />
      <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_row="3"
        android:layout_column="2"
          android:layout_marginLeft="5dp"
        android:text="9" 
        android:padding="10dp"
        />
 <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_row="3"
        android:layout_column="3"
          android:layout_marginLeft="5dp"
        android:text="9" 
        android:padding="10dp"
        />
 

</GridLayout>
转载请注明出处: http://blog.csdn.net/android_jiangjun/article/details/25164249

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值