TableLayout和我们平时在网页上见到的Table有所不同,TableLayout没有边框的,它是由多个TableRow对象组成,每个TableRow可以有0个或多个单元格,每个单元格就是一个View。这些TableRow,单元格不能设置layout_width,宽度默认是fill_parent的,只有高度layout_height可以自定义,默认是wrap_content。
单元格可以为empty,并且通过android:layout_column可以设置index值实现跳开某些单元格。在TableRow之间,添加View,设置layout_height以及背景色,就可以实现一条间隔线。android:layout_span可以设置合并几个单元格:
<?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:stretchColumns="1">
<TableRow>
<TextView android:text="用户名" android:textStyle="bold"
android:gravity="right" android:padding="3dip" />
<EditText android:id="@+id/username" android:text="用户名"
android:padding="3dip" android:scrollHorizontally="true" />
</TableRow>
<TableRow>
<TextView android:text="密码" android:textStyle="bold"
android:gravity="right" android:padding="3dip" />
<EditText android:id="@+id/password" android:text="密码"
android:password="true" android:padding="3dip"
android:scrollHorizontally="true" />
</TableRow>
<TableRow android:gravity="right">
<Button android:id="@+id/cancel" android:text="cancel" />
<Button android:id="@+id/login" android:text="login" />
</TableRow>
<!-- 间隔线 -->
<View android:layout_height="2dip" android:background="#F00" />
<View android:layout_height="5dip" />
<TableRow>
<TextView android:text="合并2个单元格" android:layout_span="2"
android:gravity="center_horizontal" android:background="#FFC0C0C0"
android:textColor="#f00" android:padding="3dip" />
</TableRow>
</TableLayout>
运行效果:
- 大小: 16.6 KB
分享到:
相关推荐
android 利用TableLayout自动生成表格
Android使用TableLayout动态布局实例: http://blog.csdn.net/lk_blog/article/details/7436380
Android-TableLayout-Example Android-TableLayout-Example
Android入门第五篇之TableLayout (二).docx
程序源代码下载 博文链接:https://greatwqs.iteye.com/blog/1045709
TableLayout跟TableLayout 是一组搭配使用的布局,TableLayout置底,TableRow在TableLayout的上面,而Button、TextView等控件就在TableRow之上,另外,TableLayout之上也可以单独放控件。TableLayout是一个使用复杂的...
Android入门第四篇之TableLayout (一).docx
android固定头部和左侧表格实现,可以实现纵向合并,不含TableLayout等布局,简单易懂
NULL 博文链接:https://hanllove001.iteye.com/blog/1185546
Tablelayout类以行和列的形式对控件进行管理,每一行为一个TableRow对象,或一个View控件。当为TableRow对象时,可在TableRow下添加子控件,默认情况下,每个子控件占据一列。 当为View时,该View将独占一行。 三个...
你可以学习下在Android开发中,tablelayout 与viewpager如何关联,如何创建每个tag标签对应的Fragment,本源码中是创建5个标题并加入布局中,实际应用中,你可以根据需要添加或减少对应的TAb布局数量。 编译时请...
TableLayout,实现动态添加和删除行,判断行中的数据是否含有空值,可以手动地输入数据,也可以选择数据添加在表格中,并实现统计表格中的数据。
TableLayout 简单程序,但不常用的话容易忘记。特此发布,以备不时之需
首先,在res下面新建一个文件夹drawable,在drawable下面新建三个xml文件:shape_corner_down.xml、shape_corner_up.xml和shape_corner.xml,分别是下面两个角是圆角边框,上面两个角是圆角...solid android:color=#0
TableLayout实现gridview嵌套gridview效果.md
利用TableLayout自定义可点击表格
android中利用tablelayout实现表格效果
Android中使用TableLayout设计的厨房装修效果的代码清单.pdf 学习资料 复习资料 教学资源
Android中使用TableLayout布局设计办公电话一览表的代码清单.pdf 学习资料 复习资料 教学资源