Android4.0新增布局GridLayout(网格布局)
2014-05-06 23:10
381 查看
网格布局由GridLayout代表,它是Android4.0新增的布局管理器,因此需要在Android4.0之后的版本中才能使用该布局管理器。
如果希望在更早的Android平台上使用该布局管理器,则需要导入相应的支撑库。
GridLayout的作用类似于HTML中的table标签,它把整个容器划分成rows*columns个网格,每个网格可以放置一个组件。除此
之外,也可以设置一个组件横跨多少列、一个组件纵跨多少行。
GridLayout提供了setRowCount(int)和setColumnCount(int)方法来控制该网格的行数量和列数量:
下面来看一下具体的使用案例:先看效果截图:
xml的相应代码如下:
如果希望在更早的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
相关文章推荐
- Android4.0后出现的网格布局:GridLayout
- Android4.0新增的网格布局
- Android4.0新增的 网格布局:计算器
- 02网格布局Gridlayout
- Java图形化界面设计——布局管理器之GridLayout(网格布局)
- 使用StaggeredGridLayoutManager实现交错式网格布局
- Java图形化界面设计——布局管理器之GridLayout(网格布局)
- 【Android】7.3 GridLayout(网格布局)
- 02网格布局Gridlayout
- 网格布局管理器GridLayout
- 「喵神成长史」『布局篇』GridLayout(网格布局)
- Android布局——GridLayout(网格布局)
- Android学习笔记(15):网格布局GridLayout
- GridLayout网格布局
- 使用StaggeredGridLayoutManager实现交错式网格布局
- 3.2.5 GridLayout(网格布局)
- 三十一、Java图形化界面设计——布局管理器之GridLayout(网格布局)
- 浅谈android4.0开发之GridLayout布局
- Android——gridLayout(网格布局)
- Android中帧布局-FrameLayout和网格布局-GridLayout