1、Andrid:控件布局(表格布局)TableLayout

    有多少个TableRow对象就有多少行,

    列数等于最多子控件的TableRow的列数

    直接在TableLayout加控件,控件会占据一行

    TableLayout属性(也叫全局属性):*代表所有列

    android:shrinkColumns -------设置可收缩的列,(内容过多,则收缩,扩展到第二行,控件没布满TableLayout时不起作用)

    android:stretchColumns ------设置可伸展的列,(有空白则填充)

    列可以同时具备stretchColumns及shrinkColumns属性

    android:collapseColumns ------设置要隐藏的列(索引列从0开始)

    内部控件属性:

    android:layout_column -------该单元格在第几列显示

    android:layout_span    -------该单元格占据列数,默认为1

 

2、布局实例:用表格实现计算机布局

      效果图

        

     代码:

  

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:stretchColumns="*"
android:layout_height="match_parent" > <TextView
android:gravity="right|center_vertical"
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:textSize="25sp"
android:text="90" /> <TableRow
android:layout_weight="1"
android:id="@+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="match_parent" > <Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="7" /> <Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="8" /> <Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="9" /> <Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="/" /> </TableRow> <TableRow
android:layout_weight="1"
android:id="@+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="match_parent" > <Button
android:id="@+id/button5"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="4" /> <Button
android:id="@+id/button6"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="5" /> <Button
android:id="@+id/button7"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="6" /> <Button
android:id="@+id/button8"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="*" /> </TableRow> <TableRow
android:layout_weight="1"
android:id="@+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="match_parent" > <Button
android:id="@+id/button9"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="1" /> <Button
android:id="@+id/button10"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="2" /> <Button
android:id="@+id/button11"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="3" /> <Button
android:id="@+id/button12"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="-" /> </TableRow> <TableRow
android:layout_weight="1"
android:id="@+id/tableRow4"
android:layout_width="wrap_content"
android:layout_height="match_parent" > <Button
android:id="@+id/button13"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="0" /> <Button
android:id="@+id/button14"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="." /> <Button
android:id="@+id/button15"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="+" /> <Button
android:id="@+id/button16"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="=" /> </TableRow> <TableRow
android:layout_weight="1"
android:id="@+id/tableRow5"
android:layout_width="wrap_content"
android:layout_height="match_parent" > <Button
android:layout_span="4"
android:id="@+id/button17"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="clear" /> </TableRow> </TableLayout>

3、使用TableLayout要注意的地方

    注意拉伸或伸展的问题,这个属性是很重要的。

        设置HorizontalScrollView的android:fillViewport="true"。也就是设置是否将HorizontalScrollView的内容宽度拉伸以适应视口(viewport)。

Android开发--布局二的更多相关文章

  1. Android开发 QRCode二维码开发第三方框架

    前言 Android开发里二维码开发经常用到,这里简单的介绍下Android开发里的二维码. 最广泛使用的二维码库zxing zxing是最广泛的二维码库各个平台都可以适用它,但是Android平台使 ...

  2. 移动应用产品开发-android开发(二)

    这段时间实在太忙了,也没什么精力来写博客,还是没养成写博客的习惯,还是得记载下来,不然时间久了就忘记了. 早上一大早就来公司了,趁还早,拟定今天的工作内容和计划后,赶紧记载点东西. 最近做androi ...

  3. Android开发——布局性能优化的一些技巧(一)

    0. 前言 上一篇我们分析了为什么LinearLayout会比RelativeLayout性能更高,意义在于分析了这两种布局的实现源码,算是对一个小结论的证明过程,但是对布局性能的优化效果,对这两种布 ...

  4. 单机搭建Android开发环境(二)

    前文介绍了如何优化SSD和内存,以发挥开发主机的最佳性能,同时提到在SSD上创建虚拟机.为什么不装双系统呢?双系统性能应该会更好!采用Windows+虚拟机的方式,主要是考虑到安卓开发和日常办公两方面 ...

  5. Android开发(二十五)——Android上传文件至七牛

    设置头像: Drawable drawable = new BitmapDrawable(dBitmap); //Drawable drawable = Drawable.createFromPath ...

  6. Android开发——布局性能优化的一些技巧(二)

    , 0, drawable.getMinimumWidth(),dra.getMinimumHeight()); tv.setCompoundDrawables(null, null, drawabl ...

  7. Android开发布局 案例二

    实践案例: XML <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:an ...

  8. Android开发(二十九)——layout_weight的含义

    首先声明只有在Linearlayout中,该属性才有效.之所以android:layout_weight会引起争议,是因为在设置该属性的同时,设置android:layout_width为wrap_c ...

  9. android开发--布局三(微信布局)

    微信主界面 我们布局应该从局来看,如上图,我们可以分为三个大的LinearLayout,再从LinearLayout嵌套其它布局,从而做出界面 文件 主界面代码: <LinearLayout x ...

随机推荐

  1. pdf 显示

    昨天调用同事写好的显示pdf借口  他返回给我的byte 我这面进行接受流的时候  长度一直跟他的对应不上 最后用WebClient类进行解决 webclient类 第一种是将文件存储在文件系统上,用 ...

  2. 黑马程序员——【Java基础】——File类、Properties集合、IO包中的其他类

    ---------- android培训.java培训.期待与您交流! ---------- 一.File类 (一)概述 1.File类:文件和目录路径名的抽象表现形式 2.作用: (1)用来将文件或 ...

  3. 一行代码从表中选取N行到另一个表

    private void Form1_Load(object sender, EventArgs e) {            DataTable dt = new DataTable();     ...

  4. Java配置环境变量

    首先,你应该已经安装了Java 的 JDK 了,笔者安装的是:jdk-7u7-windows-x64 接下来主要讲怎么配置 Java 的环境变量 1.进入“计算机”的“属性”选项后如图 2.选择“高级 ...

  5. D3 的优势

    可视化的库有很多,基于 JavaScript 开发的库也有很多,D3 有什么优势呢? (1)数据能够与 DOM 绑定在一起 D3 能够将数据与 DOM 绑定在一起,使得数据与图形成为一个整体,即图形中 ...

  6. import tf

    不知道为什么,tensorflow要最后import,否则会对matplotlib的imread产生影响,产生IO错误,异常莫名其妙

  7. tomcat切割日志的shell脚本

    #!/bin/bash cd /usr/tomcats/ d=`date +%F` m1=`date -d'1 month ago' +%F` ` do cd tomcat808"$i&qu ...

  8. IAR for msp430 MDK中 warning: #223-D: function "xxx" declared implicitly 解决方法

    今天在EINT的范例里添加了一个函数,即eint.c中添加了一个datawrite()的函数,并在主函数main.c中调用,编译便警告 warning: #223-D: function " ...

  9. (转) Graph-powered Machine Learning at Google

        Graph-powered Machine Learning at Google     Thursday, October 06, 2016 Posted by Sujith Ravi, S ...

  10. CentOS 关闭防火墙和selinux

    1)关闭防火墙(每个节点) [Bash shell] 1 2 service iptables stop chkconfig iptables off 2)关闭selinux(重启生效) [Bash ...