Android---表格布局

最简单的表格布局

 

相关代码:

 1 <GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
 2     android:layout_width="wrap_content"
 3     android:layout_height="wrap_content"
 4     android:columnCount="4"
 5     android:orientation="horizontal"
 6     android:rowCount="2" >
 7 
 8     <Button
 9         android:id="@+id/button1"
10         android:text="1" />
11 
12     <Button
13         android:id="@+id/button2"
14         android:text="2" />
15 
16     <Button
17         android:id="@+id/button3"
18         android:layout_width="wrap_content"
19         android:layout_height="wrap_content"
20         android:text="3" />
21 
22     <Button
23         android:id="@+id/button4"
24         android:text="4" />
25 
26     <Button
27         android:id="@+id/button5"
28         android:text="5" />
29 
30     <Button
31         android:id="@+id/button6"
32         android:text="6" />
33 
34     <Button
35         android:id="@+id/button7"
36         android:layout_gravity="fill_horizontal"
37         android:text="7" 
38         android:layout_columnSpan="2"/>
39 
40 </GridLayout>

网格布局常见XML属性:

•设置布局的排列对齐:
–①设置组件的排列方式:  android:orientation="vertical" (竖直,默认)或者horizontal(水平)
–②设置组件的对齐方式:  android:layout_gravity=“”  center,left,right,buttom;如果想同时用两种的话:eg: buttom|left
•设置布局为几行几列:
–①设置有多少行:android:rowCount="4"       //设置网格布局有4行
–②设置有多少列:android:columnCount="4"    //设置网格布局有4列
•设置某个组件位于几行几列(注:都是从0开始算的!)
–①组件在第几行:android:layout_row = "1"   //设置组件位于第二行
–②组件在第几列:android:layout_column = "2"   //设置该组件位于第三列
•设置某个组件横跨几行几列:
–①横跨几行:android:layout_rowSpan = "2"    //纵向横跨2行
–②横跨几列:android:layout_columnSpan = "3"     //横向横跨2列
posted @ 2016-06-22 09:16  悟知清风  阅读(291)  评论(0编辑  收藏  举报