论坛
门户
内部优惠
喜欢
话题
VIP会员
搜索
新浪微博
登录
注册
100%
100%
首页
>
软件开发
>
Android开发
>
TableLayout表格布局UI
回复
« 返回列表
灯火互联
管理员
注册日期
2011-07-27
发帖数
41778
QQ
火币
41290枚
粉丝
1086
关注
100
加关注
写私信
打招呼
阅读:
1979
回复:
0
TableLayout表格布局UI
楼主
#
更多
只看楼主
倒序阅读
发布于:2012-09-06 14:01
保存
100%
100%
[]
1
新建一个
Android
项目时,UI的默认布局是LinearLayout(线性排版),如果要要实现并排显示TextView,我们可以使用TableLayout(表格排版)。
Android
.widget.TableLayout 是一個“排版类别”,它可以将画面切割成一个表格,下面在上个工程中添加一个两列表格的例子。
编辑main.XML文件:
[html] view plaincopyprint?<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:
Android
="
http://schemas.android.com/apk/res/android
"
Android
:layout_width="fill_parent"
Android
:layout_height="fill_parent"
Android
:orientation="vertical" >
<TextView
Android
:layout_width="fill_parent"
Android
:layout_height="wrap_content"
Android
:text="@string/hello" />
<
web
View
Android
:layout_width="fill_parent"
Android
:layout_height="wrap_content"
Android
:id="@+id/wv"
/>
<TableRow>
<TextView
Android
:layout_width="fill_parent"
Android
:layout_height="wrap_content"
Android
:text="
www.atcpu.com
"
Android
:padding="5dip"
Android
:autoLink="web" />
<TextView
Android
:layout_width="fill_parent"
Android
:layout_height="wrap_content"
Android
:text="
www.atcpu.com
"
Android
:autoLink="web" />
</TableRow>
</TableLayout>
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:
Android
="
http://schemas.android.com/apk/res/android
"
Android
:layout_width="fill_parent"
Android
:layout_height="fill_parent"
Android
:orientation="vertical" >
<TextView
Android
:layout_width="fill_parent"
Android
:layout_height="wrap_content"
Android
:text="@string/hello" />
<WebView
Android
:layout_width="fill_parent"
Android
:layout_height="wrap_content"
Android
:id="@+id/wv"
/>
<TableRow>
<TextView
Android
:layout_width="fill_parent"
Android
:layout_height="wrap_content"
Android
:text="
www.atcpu.com
"
Android
:padding="5dip"
Android
:autoLink="web" />
<TextView
Android
:layout_width="fill_parent"
Android
:layout_height="wrap_content"
Android
:text="
www.atcpu.com
"
Android
:autoLink="web" />
</TableRow>
</TableLayout>
Android
.widget.TableRow配合TableRow使用的一个类,当在TableLayout添加一个TableRow时,在TableRow里面所有的View都会在同一个列(row)中显示。
为了避免同一行所有的文字都挤在一起,因此在TextView中加上padding的属性:
[html] view plaincopyprint?
Android
:padding="5dip"
Android
:padding="5dip"
表示第一个TextView的padding(间格)为5dip,表示与旁边的View有5个空格,这样就解决了两个TextView不会挤在一起。
效果如图:
摘自 Young的专栏
喜欢
0
评分
0
最新喜欢:
淘宝天猫隐藏优惠券地址
回复
100%
发帖
回复
« 返回列表
普通帖
您需要登录后才可以回帖,
登录
或者
注册
100%
返回顶部
关闭
最新喜欢