今天我们来简单的说一下Android不居中的TableLayout布局(表格布局)

  表格布局的意思就是将我们的布局看做为一个表格,主要用于对控件进行整齐排列

  我们看一个简单的案例

  

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.activitylife.MainActivity"
android:stretchColumns="*">
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="一"
android:gravity="center"
android:background="@android:color/holo_blue_dark"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="二"
android:gravity="center"
android:background="@android:color/holo_green_dark"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="三"
android:gravity="center"
android:background="@android:color/holo_blue_dark"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="四"
android:gravity="center"
android:background="@android:color/holo_green_dark"/> </TableRow> </TableLayout>

效果图

    

这里我们可以看到一个属性android:stretchColumns

  这里我们要知道TableLayout中的几个属性

  android:stretchColumns    设置可伸展的列。该列可以向行方向伸展,最多可占据一整行。

  android:shrinkColumns     设置可收缩的列。当该列子控件的内容太多,已经挤满所在行,那么该子控件的内容将往列方向显示。

  android:collapseColumns 设置要隐藏的列。

看完这些我们来看一下使用TableLayout可以做的简单的案例吧:

  

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.activitylife.MainActivity"
android:stretchColumns="*"> <TextView
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="@android:color/holo_blue_bright"
android:textSize="30dp"
android:text="0"
android:gravity="right|center"/> <TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<Button
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="1"/>
<Button
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="2"/>
<Button
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="3"/> <Button
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="+"/> </TableRow> <TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<Button
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="4"/>
<Button
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="5"/>
<Button
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="6"/> <Button
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="-"/> </TableRow> <TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<Button
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="7"/>
<Button
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="8"/>
<Button
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="9"/> <Button
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="*"/> </TableRow> <TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<Button
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="0"/>
<Button
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="."/>
<Button
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="/"/> <Button
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="="/> </TableRow> <TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<Button
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="="
android:layout_span="4"/> </TableRow> </TableLayout>

效果图:

  

最新文章

  1. HDU 3791二叉搜索树解题(解题报告)
  2. WPF 如何绘制不规则按钮,并且有效点击范围也是不规则的
  3. ICMP Protocol
  4. 单例模式-用GCD实现
  5. 使用startActivityForResult方法(转)
  6. web压力测试的轻量级具体做法
  7. 洛谷 P1040 加分二叉树
  8. iOS、mac开源项目及库汇总
  9. UltraISO制作linux启动盘(包含写入不完整解决方法)
  10. Linux显示计算次数的结果
  11. MyBatis(1)——快速入门
  12. oracle数据库之plsql可视化操作建表
  13. day44前端开发2之css基础
  14. Kafka基本架构及原理
  15. 插件: Hammer.js
  16. 最短路径——Dijkstra算法和Floyd算法
  17. Git:从github上克隆、修改和更新项目
  18. IP设置-内置服务器-外置服务器
  19. java 观察者模式 与spring配置
  20. 关于Redis命令keys在性能方面的说明

热门文章

  1. Yii2中数据过滤方案
  2. LDA的Python实现源码
  3. tp的极光推送demo
  4. SQL学习整理_2
  5. CentOS6.6安装virtualbox4.1.44
  6. 由LazyMan联想到的
  7. [Android Tips] 25. ADB Command Note
  8. React 基础入门,基础知识介绍
  9. GZIP压缩优化
  10. Windows Phone 十三、吐司通知