Android 使用 TableLayout 布局拉伸宽度
转自:http://www.cnblogs.com/ghj1976/archive/2011/04/21/2023850.html
布局文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent"> <TableLayout android:layout_width="match_parent"
android:layout_height="match_parent">
<TableRow>
<EditText android:id="@+id/et_led" android:layout_width="fill_parent"
android:digits="1234567890.+-*/=%\n\t()" android:text=""
android:layout_span="4" />
</TableRow>
<TableRow>
<Button android:text="(" android:id="@+id/btn_LeftParenthesis"></Button>
<Button android:text=")" android:id="@+id/btn_RightParenthesis"></Button>
<Button android:text="*" android:id="@+id/btn_x"></Button>
<Button android:text="back" android:id="@+id/btn_back"></Button>
</TableRow>
<TableRow>
<Button android:text="7" android:id="@+id/btn_7"></Button>
<Button android:text="8" android:id="@+id/btn_8"></Button>
<Button android:text="9" android:id="@+id/btn_9"></Button>
<Button android:text="%" android:id="@+id/btn_mod"></Button>
</TableRow>
<TableRow>
<Button android:text="4" android:id="@+id/btn_4"></Button>
<Button android:text="5" android:id="@+id/btn_5"></Button>
<Button android:text="6" android:id="@+id/btn_6"></Button>
<Button android:text="/" android:id="@+id/btn_div"></Button>
</TableRow>
<TableRow>
<Button android:text="1" android:id="@+id/btn_1"></Button>
<Button android:text="2" android:id="@+id/btn_2"></Button>
<Button android:text="3" android:id="@+id/btn_3"></Button>
<Button android:text="-" android:id="@+id/btn_sub"></Button>
</TableRow>
<TableRow>
<Button android:text="0" android:id="@+id/btn_0"></Button>
<Button android:text="." android:id="@+id/btn_dot"></Button>
<Button android:text="+" android:id="@+id/btn_plus"></Button>
<Button android:text="=" android:id="@+id/btn_equal"></Button>
</TableRow>
</TableLayout> </LinearLayout>
布局效果:

显然这不能满足我们的期望,下面我们演示 使用 android:stretchColumns 来自动拉伸
我们这里简单的给 TableLayout 增加一个属性 android:stretchColumns="*" 表示所有列都要自动拉伸,以便适应屏幕宽度。
布局效果

它的值即可以是数字,也可以是*,注意数字是从0开始的,即:android:stretchColumns="1" 是设置 TableLayout所有行的第二列为扩展列。
上面我们会看到 第四列的按钮比其他列的按钮要宽,如果我们想都一样宽如何办呢?
一个简单办法:
在自动拉伸的基础上,把每一列的宽度都设置成一样,比如下面的代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent"> <TableLayout android:layout_width="match_parent"
android:layout_height="match_parent" android:stretchColumns="*">
<TableRow>
<EditText android:id="@+id/et_led" android:layout_width="fill_parent"
android:digits="1234567890.+-*/=%\n\t()" android:text=""
android:layout_span="4" />
</TableRow>
<TableRow>
<Button android:text="(" android:id="@+id/btn_LeftParenthesis"
android:layout_width="1dip"></Button>
<Button android:text=")" android:id="@+id/btn_RightParenthesis"
android:layout_width="1dip"></Button>
<Button android:text="*" android:id="@+id/btn_x"
android:layout_width="1dip"></Button>
<Button android:text="back" android:id="@+id/btn_back"
android:layout_width="1dip"></Button>
</TableRow>
<TableRow>
<Button android:text="7" android:id="@+id/btn_7"></Button>
<Button android:text="8" android:id="@+id/btn_8"></Button>
<Button android:text="9" android:id="@+id/btn_9"></Button>
<Button android:text="%" android:id="@+id/btn_mod"></Button>
</TableRow>
<TableRow>
<Button android:text="4" android:id="@+id/btn_4"></Button>
<Button android:text="5" android:id="@+id/btn_5"></Button>
<Button android:text="6" android:id="@+id/btn_6"></Button>
<Button android:text="/" android:id="@+id/btn_div"></Button>
</TableRow>
<TableRow>
<Button android:text="1" android:id="@+id/btn_1"></Button>
<Button android:text="2" android:id="@+id/btn_2"></Button>
<Button android:text="3" android:id="@+id/btn_3"></Button>
<Button android:text="-" android:id="@+id/btn_sub"></Button>
</TableRow>
<TableRow>
<Button android:text="0" android:id="@+id/btn_0"></Button>
<Button android:text="." android:id="@+id/btn_dot"></Button>
<Button android:text="+" android:id="@+id/btn_plus"></Button>
<Button android:text="=" android:id="@+id/btn_equal"></Button>
</TableRow>
</TableLayout> </LinearLayout>
这时候的效果就成了:
注意比起最初的就多了2个设置
android:layout_width="1dip" 和 android:stretchColumns="*"

Android 使用 TableLayout 布局拉伸宽度的更多相关文章
- Android 之 TableLayout 布局详解
TableLayout简介 •简介 Tablelayout 类以行和列的形式对控件进行管理,每一行为一个 TableRow 对象,或一个 View 控件. 当为 TableRow 对象时,可在 Tab ...
- Android精通:TableLayout布局,GridLayout网格布局,FrameLayout帧布局,AbsoluteLayout绝对布局,RelativeLayout相对布局
在Android中提供了几个常用布局: LinearLayout线性布局 RelativeLayout相对布局 FrameLayout帧布局 AbsoluteLayout绝对布局 TableLayou ...
- Android之TableLayout表格布局
1.相关属性 1.1.常用属性 android:collapseColumns 设置需要被隐藏的列的序列号 android:shrinkColumns 设置允许被收缩的列的序列号 android:st ...
- android:TableLayout表格布局详解
1.TableLayout简介2.TableLayout行列数的确定3.TableLayout可设置的属性详解4.一个包含4个TableLayout布局的实例及效果图一.Tablelayout简介 ...
- 14.Android之Layout布局学习
Android布局主要有5种,接下来学习总结下. 1) 最常见的线性布局 LinearLayout 线性布局是Android布局中最简单的布局,也是最常用,最实用的布局. android:orient ...
- [置顶] Android系统五大布局详解Layout
我们知道Android系统应用程序一般是由多个Activity组成,而这些Activity以视图的形式展现在我们面前,视图都是由一个一个的组件构成的.组件就是我们常见的Button.TextEdit等 ...
- 【Android 复习】:Android五种布局的使用方法
---恢复内容开始--- 在Android布局中,有五种常用的布局,下面我们就来学习一下这几种布局的使用方式 1) 线性布局:LinearLayout 2) 帧布局: FrameLayout 3) ...
- Android系统五大布局详解Layout
我们知道Android系统应用程序一般是由多个Activity组成,而这些Activity以视图的形式展现在我们面前, 视图都是由一个一个的组件构成的.组件就是我们常见的Button.TextEdit ...
- Android视图篇之一:Android常见基本布局
Android中,布局都是直接或间接的继承自ViewGroup类,其中,ViewGroup的直接子类目前有: AbsoluteLayout, AdapterView<T extends Adap ...
随机推荐
- 【转】Linux mount/unmount命令
转自:http://www.cnblogs.com/xd502djj/p/3809375.html 格式:mount [-参数] [设备名称] [挂载点] 其中常用的参数有:-a 安装在/etc/fs ...
- 一.JSP开发的工具下载与环境搭建
JSP技术的强势: (1)一次编写,到处运行.在这一点上Java比PHP更出色,除了系统之外,代码不用做任何更改. (2)系统的多平台支持.基本上可以在所有平台上的任意环境中开发,在任意环境中进行系统 ...
- 关于Activity的少许细节
1. 对活动应用样式和主题 2. 隐藏活动标题 3. 显示对话框窗口 4. 显示进度对话框 1. 应用样式和主题 改成 android:theme="@android:style/Th ...
- 面试体验:Facebook 篇(转)
http://www.cnblogs.com/cathsfz/archive/2012/11/05/facebook-interview-experience.html 2012-11-05 08:2 ...
- C++抽象机制之二:运算符重载
1.二元运算符aa@bb,可以定义为 1).一个参数的非静态成员函数:aa.operator@(bb); (成员函数有this指针) 2). 两个参数的非成员函数:operator@(aa,bb); ...
- 50+ 响应式的Prestashop电商主题
PrestaShop是一款针对web2.0设计的全功能.跨平台的免费开源电子商务解决方案,自08年1.0版本发布,短短两年时间,发展迅速,全球已超过四万家网店采用Prestashop进行部署.Pres ...
- 自定义延时查询控件---valen
当查询已经成标配 查询是已成为每个应用常用的功能,也正是这样前端后对查询的设计需求也日益增加,本文针对前端(Android端)查询控件做一个例子: 控件设计与逻辑 产品的设计UI图; 要达到如下 1| ...
- openfire 最大连接数调优
https://community.igniterealtime.org/thread/48064#224126 https://community.igniterealtime.org/thread ...
- 第三百三十六天 how can I 坚持
家里断网了,忘交网费了,连的手机网络,也挺好,吃完饭就可以睡觉了. 不知道怎的,昨天和家人聊天,一提对象的事就很容易着急生气,然后就会后悔..哎,这脾气得改. 确实不知道自己的另一半是啥样,想象不出来 ...
- Quora的技术探索(转)
原文:http://www.cnblogs.com/xiekeli/archive/2012/04/27/2473808.html 关于问答类的应用,最早接触的是stackoverflow和知乎 ,而 ...