先来上个图,最终效果图。

每个Layout都有自己最适用的场景,而TableLayout往往用在中规中矩的输入界面,比如下图:

TableLayout下嵌套TableRow组成Table的行;每个TableRow中布局不同的控件,组成Table的列。上图就是两列四行,而我们要做的表格就是三行三列。

TableLayout是没有提供边框的,要作成表格的效果需要我们使用一些技巧:
整个TableLayout的背景色设成黑色,而每个Table的cell(其实就是每个控件)的背景色设成白色,然后cell的边距根据情况设置一个px,就可以了。
布局代码如下:

    <TableLayoutandroid:id="@+id/table"android:layout_below="@id/spinner"android:layout_width="wrap_content"android:background="@color/black"android:layout_height="wrap_content"><TableRowandroid:layout_marginTop="1dp"android:layout_marginRight="1dp"android:layout_marginLeft="1dp"android:layout_width="wrap_content"android:layout_height="wrap_content"><TextView android:text="姓名"android:textSize="@dimen/table_text_size"android:background="@color/white"android:layout_width="@dimen/table_item1_width"android:layout_height="wrap_content" /><TextView android:text="学校"android:textSize="@dimen/table_text_size"android:background="@color/white"android:layout_marginLeft="1dp"android:layout_width="@dimen/table_item2_width"android:layout_height="wrap_content" /><TextView android:text="专业"android:textSize="@dimen/table_text_size"android:background="@color/white"android:layout_marginLeft="1dp"android:layout_width="@dimen/table_item3_width"android:layout_height="wrap_content" /></TableRow><TableRowandroid:layout_marginTop="1dp"android:layout_marginBottom="1dp"android:layout_marginRight="1dp"android:layout_marginLeft="1dp"android:layout_width="wrap_content"android:layout_height="wrap_content"><TextView android:text="张飞"android:textSize="@dimen/table_text_size"android:background="@color/white"android:layout_width="@dimen/table_item1_width"android:layout_height="wrap_content" /><TextView android:text="野鸡大学"android:textSize="@dimen/table_text_size"android:background="@color/white"android:layout_marginLeft="1dp"android:layout_width="@dimen/table_item2_width"android:layout_height="wrap_content" /><TextView android:text="体育系"android:textSize="@dimen/table_text_size"android:background="@color/white"android:layout_marginLeft="1dp"android:layout_width="@dimen/table_item3_width"android:layout_height="wrap_content" /></TableRow><TableRowandroid:layout_marginBottom="1dp"android:layout_marginRight="1dp"android:layout_marginLeft="1dp"android:layout_width="wrap_content"android:layout_height="wrap_content"><TextView android:text="刘备"android:textSize="@dimen/table_text_size"android:background="@color/white"android:layout_width="@dimen/table_item1_width"android:layout_height="wrap_content" /><TextView android:text="皇家学院"android:textSize="@dimen/table_text_size"android:background="@color/white"android:layout_marginLeft="1dp"android:layout_width="@dimen/table_item2_width"android:layout_height="wrap_content" /><TextView android:text="经济"android:textSize="@dimen/table_text_size"android:background="@color/white"android:layout_marginLeft="1dp"android:layout_width="@dimen/table_item3_width"android:layout_height="wrap_content" /></TableRow></TableLayout>

Android实战技巧之三十四:用TableLayout伪装表格显示数据相关推荐

  1. Android实战技巧之三十九:短信收发

    7月4日从广州出差回来就定下写作计划,但迟迟没有动笔.耽搁的原因还是老样子,工作上又有新任务,全部精力都投入过去了,每天精疲力竭的回来也打不起精神做其他事了.这就是精力管理不当所致,就像我把很多要做的 ...

  2. Android实战技巧之十:获得屏幕物理尺寸、密度及分辨率

    大家帮忙喽! 博主参加2014博客之星活动,大家帮忙投票啦!猛击这里! 通过程序去了解硬件情况是一件十分有意思的事情.很早我就研究在WM6.5上获得屏幕物理尺寸,但一直没有成功.后来又想要在Andro ...

  3. Android实战技巧之三十七:图片的Base64编解码

    通经常使用Base64这样的编解码方式将二进制数据转换成可见的字符串格式,就是我们常说的大串.10块钱一串的那种,^_^. Android的android.util包下直接提供了一个功能十分完备的Ba ...

  4. Android实战技巧之十二:Android Studio导入第三方类库、jar包和so库

    第三方类库源码 将一网友的XMPP代码从ADT转到AS时,发现其使用了第三方类库,源码放在了lib下,直接在AS中Import project,第三方类库并没有自动导入进来,看来需要自己动手了. 项目 ...

  5. android studio导入jar包和so库,Android实战技巧之十二:Android Studio导入第三方类库、jar包和so库(示例代码)...

    第三方类库源码 将一网友的XMPP代码从ADT转到AS时,发现其使用了第三方类库,源码放在了lib下,直接在AS中Import project,第三方类库并没有自动导入进来,看来需要自己动手了. 项目 ...

  6. android 速度传感器,Android实战技巧之四十二:加速度传感器

    传感器字面上的意思就是传递感觉的仪器,哪些感觉呢? 视觉.听觉.味觉.触觉.嗅觉等等. 所以有人说,传感器的存在和发展,让物体有了触觉.味觉和嗅觉等感官,让物体慢慢变得活了起来. 当前Android设 ...

  7. Android实战技巧之四十:Android5.1.1源代码编译与烧写

    购买Nexus手机的朋友大多是为了自己修改系统玩,再加上其较高的性价比,在开发者中还是广受欢迎的.我的5太子被我升级到了6.0预览版,玩的正嗨,舍不得换回到5.1时代了.不过鉴于距6.0源码发布还有段 ...

  8. Android实战技巧之四十 Android5 1 1源代码编译与烧写

    分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow 也欢迎大家转载本篇文章.分享知识,造福人民,实现我们中华民族伟大复兴! 购买Ne ...

  9. Android实战技巧之十六:getprop与dumpsys命令

    Android设备连接PC后,我们可以通过adb命令完成绝大多数工作.下面借助getprop.dumpsys来了解一些系统相关信息. 一.getprop 此命令的原理很简单,就是从系统的各种配置文件中 ...

  10. Android实战技巧之十六 getprop与dumpsys命令

    分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow 也欢迎大家转载本篇文章.分享知识,造福人民,实现我们中华民族伟大复兴! Andr ...

最新文章

  1. 30. 多线程编程之threading模块
  2. js里规定输入的数值只能是数字
  3. 2019年,SD-WAN的回顾与展望
  4. python:将json数据写入到excel
  5. Ext.net中ComboBox如何绑定数据库中的值
  6. boost::geometry:::detail::overlay::get_clusters用法的测试程序
  7. LeetCode 1072. 按列翻转得到最大值等行数(查找相同的模式,哈希计数)
  8. Windows2003工组环境通过CA证书对加密WEB服务器
  9. dotween unity 延时_3D俯视角射击——用Unity还原东方弹幕(上)
  10. 【转】string.Format对C#字符串格式化
  11. unity通过脚本获取一个物体的所有子物体孙子物体.....并从里面找到有动画的物体
  12. 下载各种百度文库以及豆丁网文章的简便方法
  13. 入门ASP.NET Core,你该怎么学?
  14. 应该根据哪些判断云服务器的好坏
  15. 陕西省本级城镇企业退休人员 - 人脸识别APP资格认证操作指南
  16. OSChina 周六乱弹 ——什么是村支书不可推卸的责任!
  17. Totem协议(SRP/RRP)讲解PPT
  18. [高通SDM450][Android9.0]CTA认证--去掉GPS功能
  19. svn 锁死解除方案
  20. 计算机上无线网络开关在哪里,台式电脑wifi开关在哪

热门文章

  1. Win11磁盘被写保护怎么办?Win11磁盘被写保护解除方法
  2. bugku never_give_up file_get_contents()有php://input漏洞 eregi \x00绕过
  3. 彻底解决金山毒霸锁定chrome主页
  4. vue html if,vue中v-if使用方法详解
  5. Woff2字体404错误
  6. 路由器装linux系统,怎样在路由器上安装Linux / DD-WRT固件
  7. 第二重要极限公式推导过程_土木考研 土力学第八章公式推导
  8. php pdo 中dsn参数,PDO连接数据库及DSN详解
  9. python返回索引值_python取索引值
  10. 红黑联盟现场实地渗透测试培训第一期