今天我们来简单的说一下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. Enable Cross-Origin Requests in Asp.Net WebApi 2[Reprint]

    Browser security prevents a web page from making AJAX requests to another domain. This restriction i ...

  2. JavaScript第一天 改变DIV的样式

    onmouseover 当鼠标移到这个对象之上时响应 onmouseout 当鼠标移出这个对象之上时响应 document.getElementById('id')   获取id的元素并可以做一些操作 ...

  3. Hibernate 异常提示_1

    INFO: HHH000041: Configured SessionFactory: null九月 15, 2016 12:29:35 上午 org.hibernate.engine.jdbc.co ...

  4. AJAX发送参数到后台,前台火狐debug报undefine

    后面经过查找:估计是数据并不是Json格式,由于var PATIENT_ID=getIdSelections();其中PATIENT_ID是数组,所以必须转成字符串. $('#table').on(' ...

  5. itellij idea导入web项目并部署到tomcat

    概述 主要分为项目配置和tomcat配置两大步骤. 一.项目配置 打开idea,选择导入项 选择将要打开的项目路径后,继续选择项目的原本类型(后续引导设置会根据原本的项目类型更新成idea的项目),此 ...

  6. Livermore心法--策略篇

    「三三不尽,六六无穷」就是Livermore选股法的精要,以6%设关键位,3%定突破. 可是,在买卖策略方面,却不能光靠看突破就随便买入. 以Livermore的讲法,通常一只股突破前关键位后,会有轻 ...

  7. vim - save current file with a new name but keep editing current file

    http://superuser.com/questions/414110/vim-save-a-file-as-a-different-filename-but-keep-w-as-the-curr ...

  8. TestNG测试报告美化buid.xml配置

    <?xml version="1.0" encoding="UTF-8"?> <project name="myproject&qu ...

  9. iOS代码签名理解

    前言 做了几年iOS app coder了,对于证书的生成.使用流程烂熟于心,然而对于这套机制的原理却一直不甚理解.近来由于工作需要仔细研究了一下,特将自己的学习经验记录于此,以供大家学习指正. 问题 ...

  10. NOI 1.5 44:第n小的质数

    ---恢复内容开始--- 描述 输入一个正整数n,求第n小的质数. 输入 一个不超过10000的正整数n. 输出 第n小的质数. 样例输入 10 样例输出 29 方法1:合数一定可以表示成一个比它小的 ...