今天我们来简单的说一下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>

效果图:

  

Android的学习第六章(布局一TableLayout)的更多相关文章

  1. Android的学习第六章(布局一LinearLayout)

    今天我们来说一下Android五大布局-LinearLayout布局(线性布局) 含义:线性布局,顾名思义,指的是整个Android布局中的控件摆放方式是以线性的方式摆放的, 主要作用:主要对整个界面 ...

  2. Android的学习第六章(布局二--RelativeLayout)

    今天我们来说一下Android布局中的Relativelayout布局(相对布局) 根据英译过来意思是相对布局,很容易理解,这一样布局使用的是元素与元素之间的微调做到布局的 含义:通过元素与元素之间的 ...

  3. Android Animation学习(六) View Animation介绍

    Android Animation学习(六) View Animation介绍 View Animation View animation系统可以用来执行View上的Tween animation和F ...

  4. 201671010140. 2016-2017-2 《Java程序设计》java学习第六章

    java学习第六章    本周对与java中的接口,lambda表达式与内部类进行了学习,以下是我在学习中的一些体会:    1.接口: <1>.接口中的所有常量必须是public sta ...

  5. 【转载】Gradle学习 第六章:构建脚本基础

    转载地址:http://ask.android-studio.org/?/article/11 6.1. Projects and tasks 项目和任务Everything in Gradle si ...

  6. Java基础知识二次学习--第六章 常用类

    第六章 常用类   时间:2017年4月26日16:14:49~2017年4月26日16:56:02 章节:06章_01节~06章_06节 视频长度:20:57+1:15+8:44+1:26+11:2 ...

  7. C#高级编程 (第六版) 学习 第六章:运算符和类型强制转换

    第六章 运算符和类型强制转换 1,运算符 类别 运算符 算术运算符 + - * / % 逻辑运算符 & | ^ ~ && || ! 字符串连接运算符 + 增量和减量运算符 ++ ...

  8. android 项目学习随笔六(网络缓存)

    1. 对SharePreference的封装 import android.content.Context; import android.content.SharedPreferences; /** ...

  9. 深度学习框架PyTorch一书的学习-第六章-实战指南

    参考:https://github.com/chenyuntc/pytorch-book/tree/v1.0/chapter6-实战指南 希望大家直接到上面的网址去查看代码,下面是本人的笔记 将上面地 ...

随机推荐

  1. 如何添加Tomcat为启动服务

    tomcat8.0, 可以用startup.bat启动, 但注销又不能启动服务,但现在的系统不知出了什么问题 ? 答 1.我这个是zip版本的,所以里面有一个service.bat的文件,所以很简单 ...

  2. Python模拟入栈出栈操作

    目标: 1.编写菜单,提示用户操作选项(push,pop,view,quit) 2.规则:定义列表,先入栈,后出栈,后入栈,先出栈 1.模拟入栈.出栈操作 >>> list1 = [ ...

  3. 移动应用抓包调试利器Charles

    转载:http://www.jianshu.com/p/68684780c1b0 一.Charles是什么? Charles是在 Mac或Windows下常用的http协议网络包截取工具,是一款屌的不 ...

  4. javascript DOM 操作 attribute 和 property 的区别

    javascript DOM 操作 attribute 和 property 的区别 在做 URLRedirector 扩展时,注意到在使用 jquery 操作 checkbox 是否勾选时,用 at ...

  5. Android下读取logcat的信息

    有时我们需要在程序执行进程中遇到一些异常,需要收集一logcat的信息,android下就可以使用以下方法获取: private static String getLogcatInfo(){ Stri ...

  6. python操作word入门

    1.安装pywin32 http://sourceforge.net/projects/pywin32 在files里去找适合你的python版本.截止此文,最新版本是pywin32-219快捷路径: ...

  7. ActiveMQ 复杂类型的发布与订阅

    很久没po文章了,但是看到.Net里关于ActiveMQ发送复杂类型的文章确实太少了,所以贴出来和大家分享 发布: //消息发布 public class Publisher { private IC ...

  8. OpenERP 使用与开发笔记(一)

    一直关注OpenERP,但一直未真正使用.最近一些数据想规范管理,免得使和EXCEL与WORD等到处找,所以想到OpenERP的自定义功能比较好,就再次找来相关资料重新拾掇起来.在这过程中,发现了许多 ...

  9. hdu5713 K个联通块[2016百度之星复赛B题]

    dp 代码 #include<cstdio> ; ; int n,m,k,cnt[N]; ]; ][],i,j,l,a,b; int check(int x,int y) { int i; ...

  10. swift基础:第三部分:对第一部分的补充说明

    今天是我学习swift的第二天,虽然我和swift的距离有点远,但我相信,我会慢慢的接近这门语言的.好了,我们聊聊昨天晚上的事吧,昨天晚上下班早,回到家时,真是惊喜哈,宿舍那两做好了饭,等我吃饭,想对 ...