UI组件——GridLayout
2016-04-18 00:00
567 查看
1 GridLayout(网格布局) 在Android4.0开始引入。
GridLayout可以把布局分为几行和几列。
GridLayout可以设置一个组件横框多少行,纵夸多少列。
GridLayout和TableLayout很相似,但是如果要设计行列布局,GridLayout使用更方便、更高效。因为:
GridLayout
works with a flat-view hierarchy, where child views set their locations in the grid by specifying the rows and columns they should be in. By maintaining a flat hierarchy, GridLayout is able to more swiftly layout its child views.
The new GridLayout control for Android 4.0 is very powerful and we've just scratched the surface of what it can do
2 GridLayout常见属性
GridLayout常用的XML属性和方法说明
GridLayout.LayoutParams常用的XML属性和方法说明
说明:
(1) Gridlayout 的默认对齐方式是
android:orientation="horizontal"。
<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:rowCount="2"
android:columnCount="2">
<TextView
android:text="Cell 0"
android:textSize="14dip" />
<TextView
android:text="Cell 1"
android:textSize="14dip" />
<TextView
android:text="Cell 2"
android:textSize="14dip" />
<TextView
android:text="Cell 3"
android:textSize="14dip" />
</GridLayout>
The layout will adjust the row and column sizes so that the cells can fit their content, as illustrated by the following diagram:
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:rowCount="2"
android:columnCount="2"
android:orientation="vertical">
</GridLayout>
Now, the GridLayout will position the cells from top to bottom in each column, instead of left to right, as shown below:
(2)
layout_gravity,android:layout_row , android:layout_column and layout_textSise等
attribute can also adjust the size。
(3) layout_gravity attribute can also adjust the size。
<Button
android:layout_columnSpan="2"
android:text="0"/>
<Button
android:layout_columnSpan="3"
android:layout_gravity="fill"
android:text="="/>
Ref:
http://code.tutsplus.com/tutorials/android-user-interface-design-creating-a-numeric-keypad-with-gridlayout--mobile-8677
http://www.tuicool.com/articles/Rr2EfmA
GridLayout可以把布局分为几行和几列。
GridLayout可以设置一个组件横框多少行,纵夸多少列。
GridLayout和TableLayout很相似,但是如果要设计行列布局,GridLayout使用更方便、更高效。因为:
GridLayout
works with a flat-view hierarchy, where child views set their locations in the grid by specifying the rows and columns they should be in. By maintaining a flat hierarchy, GridLayout is able to more swiftly layout its child views.
The new GridLayout control for Android 4.0 is very powerful and we've just scratched the surface of what it can do
2 GridLayout常见属性
GridLayout常用的XML属性和方法说明
XML属性 | 相关方法 | 说明 |
---|---|---|
android:alignmentMode | setAlignmentMode(int) | 设置该布局管理器采用的对齐模式 |
android:rowCount | setRowCount(int) | 设置该网格的行数 |
android:columnCount | setColumnCount(int) | 设置该网格的列数量 |
android:rowOrderPreserved | setRowOrderPreserved(boolean) | 设置该网格容器是否保留行序号 |
android:columnOrderPreserved | setColumnOrderPreserved(boolean) | 设置该网格容器是否保留序列号 |
android:useDefaultMargins | setUseDefaultMargins(boolean) | 设置该布局管理器是否使用默认的页边距 |
XML属性 | 相关方法 | 说明 |
---|---|---|
android:layout_column | 略 | 设置该组件在GridLayout的第几列 |
android:layout_columnSpan | 略 | 设置该子组件在GridLayout横向上跨几列 |
android:layout_gravity | 略 | 设置该子组件采用何种方式占据该网格的空间 |
android:layout_row | 略 | 设置该子组件在GridLayout的第几行 |
android:layout_rowSpan | 略 | 设置该子组件在GridLayout纵向上跨几行 |
android:orientation | 略 | 略 |
(1) Gridlayout 的默认对齐方式是
android:orientation="horizontal"。
<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:rowCount="2"
android:columnCount="2">
<TextView
android:text="Cell 0"
android:textSize="14dip" />
<TextView
android:text="Cell 1"
android:textSize="14dip" />
<TextView
android:text="Cell 2"
android:textSize="14dip" />
<TextView
android:text="Cell 3"
android:textSize="14dip" />
</GridLayout>
The layout will adjust the row and column sizes so that the cells can fit their content, as illustrated by the following diagram:
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:rowCount="2"
android:columnCount="2"
android:orientation="vertical">
</GridLayout>
Now, the GridLayout will position the cells from top to bottom in each column, instead of left to right, as shown below:
(2)
layout_gravity,android:layout_row , android:layout_column and layout_textSise等
attribute can also adjust the size。
(3) layout_gravity attribute can also adjust the size。
<Button
android:layout_columnSpan="2"
android:text="0"/>
<Button
android:layout_columnSpan="3"
android:layout_gravity="fill"
android:text="="/>
Ref:
http://code.tutsplus.com/tutorials/android-user-interface-design-creating-a-numeric-keypad-with-gridlayout--mobile-8677
http://www.tuicool.com/articles/Rr2EfmA
相关文章推荐
- in_array,最好将第三个参数设置为true
- UITouch
- concurrent 包 BlockingQueue
- 【Notes on Neural Networks and Deep Learning】(to be continued)
- 南京理工大学第八届程序设计大赛 F sequence
- NSOprationQueue 与 GCD 的区别与选用
- UICollectionViewLayout
- javax.servlet.ServletException: java.lang.IllegalStateException: Queue full
- iOS8自动调整UITableView和UICollectionView布局
- UICollectionView自定义Layout之蜂窝布局
- JSP中pageEncoding、charset=UTF-8及request/response
- 百度编辑器ueditor 异步加载时,初始化没办法赋值bug解决方法
- Java设置GUI的窗口图标
- priority_queue的用法
- 1.for(;;) 与 while(true) 的 区别
- (OK) digui-gb18030-utf8.sh——递归
- Zookeeper安装配置及可视化ZKUI安装配置(zookeeper3.4.6)
- [Java拾遗四]JavaWeb基础之Servlet_Request&&Response
- 使用uiautomator做UI测试
- (OK) digui-dir-del-M.sh——递归