Android UI之GridLayout(网格布局)
2015-05-15 07:43
393 查看
说明:网格布局是4.0之后添加的布局,跟TableLayout有点像,但更加好用,它把容器分为一个rows*columns的网格,每个网格都是一个组件位,可是通过设置让组件位占据多行/列。
与之相似地,还有一个叫做GridView的组件,无论功能和名称都很相似,不过GridView使用Adapter来填充组件位,GridLayout则要简化得多。
按照CSDN博主studyboyjlu4(博客地址:http://blog.csdn.net/studyboyjlu4)的看法,GridView和GridLayout的区别就和ListView和LinearLayout的区别类似。
GridLayout有两类需要关注的属性:
属性表如下:
[thead]
属性表如下:
[thead]
这里的LayoutGravity跟一般的LayoutGravity有点区别,这里的摆放位置是相对于所属网格的,而不是对于布局父容器来说的。
《疯狂Android讲义(第二版)》 李刚 《2.2.5 Android4.0新增的网格布局》 电子工业出版社
与之相似地,还有一个叫做GridView的组件,无论功能和名称都很相似,不过GridView使用Adapter来填充组件位,GridLayout则要简化得多。
按照CSDN博主studyboyjlu4(博客地址:http://blog.csdn.net/studyboyjlu4)的看法,GridView和GridLayout的区别就和ListView和LinearLayout的区别类似。
GridLayout有两类需要关注的属性:
1 GridLayout本身的属性
说明:这类属性是针对GridLayout自身来设置的,主要是对行和列,以及对其方式的设置。属性表如下:
属性 | 对应方法 | 属性说明 |
---|---|---|
android:columnCount | setColumCount(int) | 设置布局的最大列数 |
android:rowCount | setRowCount(int) | 设置布局的最大行数 |
android:alignmentMode | setAilgnmentMode(int) | 设置布局的对其方式(alignBounds: 对齐子视图边界;alignMargins: 对齐子视图边距;) |
android:columnOrderPeserved | setColumOrderPreserved(boolean) | 设置容器是否保留列序号 |
android:rowOrderPeserved | setRowOrderPeserved(boolean) | 设置容器是否保留行序号 |
android:useDefaultMargins | setUseDefaultMargins(boolean) | 设置容器是否使用默认的页边距 |
2 针对容器内的子组件的属性
说明:这类属性是针对GridLayout中的子组件设置的,可以设置组件在网格中的大小和摆放方式。属性表如下:
属性 | 对应方法 | 属性说明 |
---|---|---|
android:layout_Gravity | setGravity(int) | 设置组件如何占据其所属网格的空间 |
android:layout_column | 设置组件在容器的第几列 | |
android:layout_row | 设置组件在容器的第几行 | |
android:layout_columnSpan | 设置组件占据了几列 | |
android:layout_rowSpan | 设置组件占据了几行 |
<GridLayout android:columnCount="4" android:id="@+id/root1" android:layout_width="fill_parent" android:layout_height="fill_parent"> <ImageView android:layout_rowSpan="2" android:layout_width="100dp" android:layout_height="200dp" android:background="#600096" /> <ImageView android:layout_columnSpan="2" android:layout_width="200dp" android:layout_height="100dp" android:background="#006096" /> <ImageView android:layout_rowSpan="2" android:layout_width="100dp" android:layout_height="50dp" android:layout_gravity="bottom" android:background="#009660" /> <ImageView android:layout_columnSpan="2" android:layout_rowSpan="2" android:layout_width="200dp" android:layout_height="300dp" android:background="#960060" /> <ImageView android:layout_width="100dp" android:layout_height="200dp" android:background="#AA6060" /> <ImageView android:layout_width="100dp" android:layout_height="200dp" android:background="#AA55AA" /> </GridLayout>
附:引用声明
studyboyjlu4的专栏:GridLayout和GridView的区别《疯狂Android讲义(第二版)》 李刚 《2.2.5 Android4.0新增的网格布局》 电子工业出版社
相关文章推荐
- android 4.0引入的新布局GridLayout(网格布局)
- Android零基础入门第32节:新推出的GridLayout网格布局
- [置顶] Android--(9)--详解网格布局(GridLayout)
- Android开发7:布局管理器4(网格布局GridLayout,绝对布局AbsoluteLayout)
- Android实现计算器布局(四种布局方式)之GridLayout网格布局
- 【Android】7.3 GridLayout(网格布局)
- Android基础入门教程——2.2.5 GridLayout(网格布局)
- Android基础入门教程——2.2.5 GridLayout(网格布局)
- (五)Android布局之网格布局(GridLayout)
- Android零基础入门第32节:新推出的GridLayout网格布局
- 第16章、布局Layouts之GridLayout网格布局(从零开始学Android)
- android之网格布局GridLayout
- Android学习 9-> 表格布局TableLayout和网格布局GridLayout
- Android布局之GridLayout网格布局
- Android零基础入门第32节:新推出的GridLayout网格布局
- android之网格布局GridLayout
- 第16章、布局Layouts之GridLayout网格布局(从零开始学Android)
- android之网格布局GridLayout
- Android开发——GridLayout网格布局