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列

转载于:https://www.cnblogs.com/s1-myblog/p/5605894.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值