- 浏览: 169185 次
- 性别:
- 来自: 北京
-
最新评论
-
wangzhengfu:
看你这文章很纠结,既然把图贴出来了,为啥不贴上代码呢
android EditText 去除边框 -
sovio:
...
android EditText 去除边框 -
kdac:
啥J8翻译啊,谷歌翻译贴出来的吧?翻译不了就放原文,不伦不类, ...
android 弹出软键盘将底部视图顶起问题 -
shiny_txdd:
17:34:47,806 ERROR [ContextLoad ...
tomcat项目转jboss5.0 -
lenomon:
这里有篇实现无下划线的,Android使用TextView实现 ...
Android TextView中文字设置超链接、颜色、字体
Just like HTML Tables on webpages the TableLayout on Android gives you the option to align Views in a table order with rows and columns.
My development setup is:
IDE: Eclipse IDE (setup guide here
).
Phone: HTC Hero
Android version: 1.5 HTC Rom
I will be using the standard Android Project Skeleton in Eclipse as my base setup. This auto creates all the basic files needed, so these will not be covered here.
TableLayout on Android
The TableLayout is built using the TableLayout and the TableRow commands. There is no TableCols like the <td> tag in HTML. To align your view in columns you have to set the width of the elements and manually control the layout.
XML Layout
To make a basic layout with 2 rows and 4 textview I have a main.xml with this content:
<
TableLayout
android:id
=
"@+id/TableLayout01"
android:layout_width
=
"wrap_content"
android:layout_height
=
"wrap_content"
>
<
TableRow
android:id
=
"@+id/TableRow01"
android:layout_width
=
"wrap_content"
android:layout_height
=
"wrap_content"
>
<
TextView
android:id
=
"@+id/TextView01"
android:layout_width
=
"wrap_content"
android:layout_height
=
"wrap_content"
android:text
=
"textfield 1-1"
></
TextView
>
<
TextView
android:id
=
"@+id/TextView02"
android:layout_width
=
"wrap_content"
android:layout_height
=
"wrap_content"
android:text
=
"textfield 1-2"
></
TextView
>
</
TableRow
>
<
TableRow
android:id
=
"@+id/TableRow02"
android:layout_width
=
"wrap_content"
android:layout_height
=
"wrap_content"
>
<
TextView
android:id
=
"@+id/TextView03"
android:layout_width
=
"wrap_content"
android:layout_height
=
"wrap_content"
android:text
=
"textfield 2-1"
></
TextView
>
<
TextView
android:id
=
"@+id/TextView04"
android:layout_width
=
"wrap_content"
android:layout_height
=
"wrap_content"
android:text
=
"textfield 2-2"
></
TextView
>
</
TableRow
>
</
TableLayout
>
|
This creates a layout like this:
So we have now displayed a simple TableLayout.
Right aligning checkboxes
Many apps have a nice clean setup where the checkboxes is right aligned to the screen and this is actually very easy to achieve. You just have to set the width of the textview so it will push the checkbox to the right.
First step is to change the TextView02 to a Checkbox like this:
...
<
TextView
android:id
=
"@+id/TextView01"
android:layout_width
=
"wrap_content"
android:layout_height
=
"wrap_content"
android:text
=
"textfield 1-1"
></
TextView
>
<
CheckBox
android:id
=
"@+id/CheckBox01"
android:layout_width
=
"wrap_content"
android:layout_height
=
"wrap_content"
></
CheckBox
>
|
This will output somethings like this:
Now we just have to align the checkbox.
We can do this by setting the width of the previous textfield like this:
<
TableRow
android:id
=
"@+id/TableRow01"
android:layout_width
=
"wrap_content"
android:layout_height
=
"wrap_content"
><
TextView
android:id
=
"@+id/TextView01"
android:layout_width
=
"wrap_content"
android:layout_height
=
"wrap_content"
android:text
=
"textfield 1-1"
android:width
=
"250px"
></
TextView
>
|
Notice the width=”250px”
in the end there. This results in:
But what is the screen size changes? The checkbox will then be placed 250px from the left because the width is hardcoded. Not that great – but yet very easy to adjust.
On the LayoutTable we can adjust stretching across columns, similar to the colspan tag in HTML.
...
<
TableLayout
android:id
=
"@+id/TableLayout01"
android:layout_width
=
"fill_parent"
android:layout_height
=
"wrap_content"
android:stretchColumns
=
"0"
>
...
|
This will make the first (“0″) column stretch as most as needed and allowed by the other elements.:
And with the screen flipped:
Complete XML layout:
<?
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
android:orientation
=
"vertical"
android:layout_width
=
"fill_parent"
android:layout_height
=
"fill_parent"
>
<
TableLayout
android:id
=
"@+id/TableLayout01"
android:layout_width
=
"fill_parent"
android:layout_height
=
"wrap_content"
android:stretchColumns
=
"0"
>
<
TableRow
android:id
=
"@+id/TableRow01"
android:layout_width
=
"wrap_content"
android:layout_height
=
"wrap_content"
>
<
TextView
android:id
=
"@+id/TextView01"
android:layout_width
=
"fill_parent"
android:layout_height
=
"wrap_content"
android:text
=
"textfield 1-1"
></
TextView
>
<
CheckBox
android:id
=
"@+id/CheckBox01"
android:layout_width
=
"wrap_content"
android:layout_height
=
"wrap_content"
></
CheckBox
>
</
TableRow
>
<
TableRow
android:id
=
"@+id/TableRow02"
android:layout_width
=
"wrap_content"
android:layout_height
=
"wrap_content"
>
<
TextView
android:id
=
"@+id/TextView03"
android:layout_width
=
"wrap_content"
android:layout_height
=
"wrap_content"
android:text
=
"textfield 2-1"
></
TextView
>
<
TextView
android:id
=
"@+id/TextView04"
android:layout_width
=
"wrap_content"
android:layout_height
=
"wrap_content"
android:text
=
"textfield 2-2"
></
TextView
>
</
TableRow
>
</
TableLayout
>
</
LinearLayout
>
|
Appending rows dynamically
Lets say you want to add rows to the TableLayout on depend during your app. No problem.
Add a button at the top of your application like this:
<
Button
android:id
=
"@+id/Button01"
android:layout_width
=
"wrap_content"
android:layout_height
=
"wrap_content"
android:text
=
"Add row"
></
Button
>
<
ScrollView
android:id
=
"@+id/ScrollView01"
android:layout_width
=
"wrap_content"
android:layout_height
=
"wrap_content"
>
<
TableLayout
android:id
=
"@+id/TableLayout01"
android:layout_width
=
"fill_parent"
android:layout_height
=
"wrap_content"
android:stretchColumns
=
"0"
>
<
TableRow
android:id
=
"@+id/TableRow01"
android:layout_width
=
"wrap_content"
android:layout_height
=
"wrap_content"
>
<
TextView
android:id
=
"@+id/TextView01"
android:layout_width
=
"fill_parent"
android:layout_height
=
"wrap_content"
android:text
=
"textfield 1-1"
></
TextView
>
<
CheckBox
android:id
=
"@+id/CheckBox01"
android:layout_width
=
"wrap_content"
android:layout_height
=
"wrap_content"
></
CheckBox
>
</
TableRow
>
</
TableLayout
>
</
ScrollView
>
|
There is now a button available for handling clicks from the user and the TableLayout has been wrapped in a ScrollView which enables the scroll functionality.
Now for some Java code
package
huuah.tablelayout;
import
android.app.Activity;
import
android.os.Bundle;
import
android.widget.TableLayout;
import
android.widget.TextView;
import
android.view.View;
import
android.view.View.OnClickListener;
import
android.widget.Button;
import
android.widget.CheckBox;
import
android.widget.TableRow;
import
android.widget.TableRow.LayoutParams;
public
class
tablelayout
extends
Activity
implements
OnClickListener {
/** Called when the activity is first created. */
//initialize a button and a counter
Button btn;
int
counter =
0
;
@Override
public
void
onCreate(Bundle savedInstanceState) {
super
.onCreate(savedInstanceState);
// setup the layout
setContentView(R.layout.main);
// add a click-listener on the button
btn = (Button) findViewById(R.id.Button01);
btn.setOnClickListener(
this
);
}
// run when the button is clicked
public
void
onClick(View view) {
// get a reference for the TableLayout
TableLayout table = (TableLayout) findViewById(R.id.TableLayout01);
// create a new TableRow
TableRow row =
new
TableRow(
this
);
// count the counter up by one
counter++;
// create a new TextView
TextView t =
new
TextView(
this
);
// set the text to "text xx"
t.setText(
"text "
+ counter);
// create a CheckBox
CheckBox c =
new
CheckBox(
this
);
// add the TextView and the CheckBox to the new TableRow
row.addView(t);
row.addView(c);
// add the TableRow to the TableLayout
table.addView(row,
new
TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
}
}
|
So whenever the button is clicked, it adds a new row to the TableLayout and notice the Scrollbar from the ScrollView.
If you want more information and TableLayout and placement techniques I can recommend reading:
Thats it for now. Enjoy coding and please post some comments.
原文:http://huuah.com/using-tablelayout-on-android/
发表评论
-
Android中canvas和paint的关系及使用
2011-11-30 10:15 2244刚刚开始接触学习Android的同鞋们在看到工程中出现的那么 ... -
Android 模仿renren的左右划动菜单栏
2011-11-10 13:47 2552模仿renren的左右划动菜单栏,主要通过Horizo ... -
android 抓包
2011-07-12 10:28 39751、下载TcpDump for Android ,或者本地下 ... -
Android参数设置父布局集体宽高
2011-06-21 11:47 3429LinearLayout gridContainer = (L ... -
Android应用按返回键完全退出应用
2011-06-07 17:58 7227很多网友可能发现自己 ... -
GIT和repo使用方法,下载android-2.6.29内核
2011-06-07 14:45 1995http://hi.baidu.com/kkernel/ ... -
如何申请 android google map API key
2011-06-01 15:16 16191.首先要得到你的debug keystore位置: 打 ... -
Android TextView中文字设置超链接、颜色、字体
2011-05-27 12:27 5386TextView是用来显示文本的,有时需要给TextView中 ... -
设置ProgressBar的颜色
2011-05-26 10:05 2258在《Android/OPhone开发完全讲义》 ... -
Android 调用系统的照相,浏览图片,转存并裁剪!
2011-05-25 12:59 4601public class AddCardActivity ex ... -
修改TabHost默认样式
2011-05-10 13:52 3200TabHost是Android提供的一个容器组件, ... -
Android控件美化Shape
2011-05-04 09:59 1210当然除了使用drawable这样的图片外今天谈下自定义图形 ... -
android开发中WebView的使用(附完整程序)
2011-05-03 14:00 2115WebView是个好东西,作用相当于一个迷你的浏览器,采用We ... -
android 弹出软键盘将底部视图顶起问题
2011-04-19 13:20 6960今天要做一个搜索功能,搜索界面采用AutoCompleteTe ... -
自定义ListView行间的分割线
2011-04-18 10:18 1607在Android平台中系统控件提供了灵活的自定义选项,所有 ... -
android xml中应用占位符
2011-04-02 18:24 1569Formatting and Styling Here ar ... -
android Toast大全(五种情形)建立属于你自己的Toast
2011-04-02 18:18 934Toast用于向用户显示一些帮助/提示。下面我做了5中效果,来 ... -
JadEclipse工具的使用
2011-04-01 11:49 2568JadEclipse工具的使用 1、下载工具 JadEcl ... -
Android 反编译apk 到java源码的方法
2011-04-01 11:20 969Android由于其代码是放在dalvik虚拟机上的托管代码, ... -
Android dex ,xml 文件反编译方法【转】
2011-04-01 11:19 1523Dex 文件是Android上运行于delvik的java二进 ...
相关推荐
基于万能逼近原理的自适应模糊控制算法在多自由度AUV运动控制中的应用与抗干扰补偿Simulink仿真研究,自适应模糊控制算法的万能逼近原理与多自由度AUV运动控制的抗干扰补偿技术——基于Simulink的仿真研究,万能逼近原理自适应模糊控制算法的多自由度AUV运动控制抗干扰补偿simulink仿真 ,核心关键词:万能逼近原理; 自适应模糊控制算法; 多自由度AUV运动控制; 抗干扰补偿; Simulink仿真。,基于万能逼近的模糊控制算法多自由度AUV抗干扰补偿Simulink仿真
deepseek最新资讯、配置方法、使用技巧,持续更新中
deepseek最新资讯、配置方法、使用技巧,持续更新中
结合扩展卡尔曼滤波与滑模观测器的策略:优化电角度估计,反电势波形逼近完美正弦波,结合扩展卡尔曼滤波与滑模观测器的反电势波形优化:正弦波形展现近乎完美精度,电角度估算与实际应用差异微小,扩展卡尔曼滤波与滑模观测器的结合,反电势波形近乎完美的正弦波形,观测器估算转子电角度与实际电角度相差0.3弧度左右,转速跟随效果较好。 ,核心关键词:扩展卡尔曼滤波; 滑模观测器; 反电势波形; 转子电角度估算; 转速跟随效果。,卡尔曼滑模观测器:优化正弦波转子角度与转速估算
毕业设计_基于springboot+vue的**学生公寓管理系统**【源码+sql+可运行】【**50217**】.zip 全部代码均可运行,亲测可用,尽我所能,为你服务; 1.代码压缩包内容 代码:springboo后端代码+vue前端页面代码; 脚本:数据库SQL脚本 效果图:运行结果请看资源详情效果图 2.环境准备: - JDK1.8+ - maven3.6+ - nodejs14+ - mysql5.6+ - redis 3.技术栈 - 后台:springboot+mybatisPlus+Shiro - 前台:vue+iview+Vuex+Axios - 开发工具: idea、navicate 4.功能列表 - 系统设置:用户管理、角色管理、资源管理、系统日志 - **业务管理:业务管理:公寓信息、房间信息、入住记录、学生信息** 3.运行步骤: 步骤一:修改数据库连接信息(ip、port修改) 步骤二:找到启动类xxxApplication启动 4.若不会,可私信博主!!!
1、文件内容:xorg-x11-server-source-1.20.4-29.el7_9.rpm以及相关依赖 2、文件形式:tar.gz压缩包 3、安装指令: #Step1、解压 tar -zxvf /mnt/data/output/xorg-x11-server-source-1.20.4-29.el7_9.tar.gz #Step2、进入解压后的目录,执行安装 sudo rpm -ivh *.rpm 4、更多资源/技术支持:公众号禅静编程坊
1、文件内容:yum-plugin-ps-1.1.31-54.el7_8.rpm以及相关依赖 2、文件形式:tar.gz压缩包 3、安装指令: #Step1、解压 tar -zxvf /mnt/data/output/yum-plugin-ps-1.1.31-54.el7_8.tar.gz #Step2、进入解压后的目录,执行安装 sudo rpm -ivh *.rpm 4、更多资源/技术支持:公众号禅静编程坊
基于模型预测控制(MPC)的无人船与无人车编队一致性协同控制研究(附原文献),基于模型预测控制(MPC)的无人船与无人车编队一致性协同控制研究(附原文献),无人船编队 无人车编队 MPC 模型预测控制 多智能体协同控制 一致性 MATLAB 无人车 USV 带原文献 ,无人船编队; 无人车编队; MPC 模型预测控制; 多智能体协同控制; 一致性; MATLAB; USV; 原文献,无人系统协同控制:MPC模型预测控制下的多智能体编队与一致性研究(原文献支撑)
4套中级通信工程师综合真题及答案(2019,2020,2021,2023),适用于需要考中级通信工程师的人群
deepseek最新资讯,配置方法,使用技巧,持续更新中
基于matlab的锁相环PLL相位噪声拟合仿真代码集合:多个版本建模与仿真,高质量的锁相环PLL仿真代码集合:Matlab与Simulink建模研究,[1]锁相环 PLL 几个版本的matlab相位噪声拟合仿真代码,质量杠杠的,都是好东西 [2]锁相环matlab建模稳定性仿真,好几个版本 [3]锁相环2.4G小数分频 simulink建模仿真 ,PLL; Matlab相位噪声拟合仿真; Matlab建模稳定性仿真; 锁相环2.4G小数分频Simulink建模仿真,MATLAB仿真系列:锁相环PLL及分频器建模仿真
exceptionLogs.zip
基于光伏微网的经济性与并网负荷波动率双目标优化调度策略:蓄电池与V2G协同管理策略仿真研究,MATLAB下光储充微网结合电动汽车V2G的多目标协同调度策略研究:经济性与并网负荷波动性的对比分析,MATLAB代码:考虑V2G的光储充一体化微网多目标优化调度策略 关键词:光储充微网 电电汽车V2G 多目标优化 蓄电池优化 调度 参考文档:《光伏微网下考虑V2G补偿蓄电池容量的双目标优化调度策略》,已经投稿EI会议,中文说明文档可联系我咨询 仿真平台:MATLAB 平台 优势:代码注释详实,适合参考学习,相关成果已经采用,程序非常精品,请仔细辨识 主要内容:过建立光伏微网中以经济性和并网负荷波动率为双目标的蓄电池和V2G的协同调度模型。 采用粒子群算法,对电网、微网调度中心和电动汽车用户三方在无、无序、转移和调度V2G电动汽车负荷四种运行模式下的经济和安全影响进行对比。 最后,根据算例分析,求解四种模式下两级负荷曲线及经济收益表。 对比分析得出,引入V2G可以替代部分容量的蓄电池,使光伏微网在负荷峰谷平抑、三方经济和安全等方面进一步优化。 求解采用的是PSO算法(粒子群算法),求解效果极
javascript 动态网页设计期末大作业(自己手写的,高分期末作业),含有代码注释,新手也可看懂,个人手打98分项目,导师非常认可的高分项目,毕业设计、期末大作业和课程设计高分必看,下载下来,简单部署,就可以使用。该项目可以直接作为毕设、期末大作业使用,代码都在里面,系统功能完善、界面美观、操作简单、功能齐全、管理便捷,具有很高的实际应用价值,项目都经过严格调试,确保可以运行! javascript 动态网页设计期末大作业(自己手写的,高分期末作业)javascript 动态网页设计期末大作业(自己手写的,高分期末作业)javascript 动态网页设计期末大作业(自己手写的,高分期末作业)javascript 动态网页设计期末大作业(自己手写的,高分期末作业)javascript 动态网页设计期末大作业(自己手写的,高分期末作业)javascript 动态网页设计期末大作业(自己手写的,高分期末作业)javascript 动态网页设计期末大作业(自己手写的,高分期末作业)javascript 动态网页设计期末大作业(自己手写的,高分期末作业)javascript 动态网页设计期
混合智能体系统编队控制:分布式优化与15异构混合阶的挑战,异构混合阶智能体系统编队控制的分布式优化策略研究,15异构混合阶多智能体系统编队控制的分布式优化(无参考文献) ,核心关键词:15异构混合阶; 多智能体系统; 编队控制; 分布式优化; 无参考文献。,15混合阶多智能体系统编队分布式优化控制
javascript 动态网页设计期末大作业(自己手写的,很适合期末作业),含有代码注释,新手也可看懂,个人手打98分项目,导师非常认可的高分项目,毕业设计、期末大作业和课程设计高分必看,下载下来,简单部署,就可以使用。该项目可以直接作为毕设、期末大作业使用,代码都在里面,系统功能完善、界面美观、操作简单、功能齐全、管理便捷,具有很高的实际应用价值,项目都经过严格调试,确保可以运行! javascript 动态网页设计期末大作业(自己手写的,很适合期末作业)javascript 动态网页设计期末大作业(自己手写的,很适合期末作业)javascript 动态网页设计期末大作业(自己手写的,很适合期末作业)javascript 动态网页设计期末大作业(自己手写的,很适合期末作业)javascript 动态网页设计期末大作业(自己手写的,很适合期末作业)javascript 动态网页设计期末大作业(自己手写的,很适合期末作业)javascript 动态网页设计期末大作业(自己手写的,很适合期末作业)javascript 动态网页设计期末大作业(自己手写的,很适合期末作业)javascrip
X光安检OPIXray数据集已经转换为VOC格式,可直接转换为为YOLO
DataX--Web:图形化界面简化大数据任务管理_datax-web
# 踏入C语言的奇妙编程世界 在编程的广阔宇宙中,C语言宛如一颗璀璨恒星,以其独特魅力与强大功能,始终占据着不可替代的地位。无论你是编程小白,还是有一定基础想进一步提升的开发者,C语言都值得深入探索。 C语言的高效性与可移植性令人瞩目。它能直接操控硬件,执行速度快,是系统软件、嵌入式开发的首选。同时,代码可在不同操作系统和硬件平台间轻松移植,极大节省开发成本。 学习C语言,能让你深入理解计算机底层原理,培养逻辑思维和问题解决能力。掌握C语言后,再学习其他编程语言也会事半功倍。 现在,让我们一起开启C语言学习之旅。这里有丰富教程、实用案例、详细代码解析,助你逐步掌握C语言核心知识和编程技巧。别再犹豫,加入我们,在C语言的海洋中尽情遨游,挖掘无限可能,为未来的编程之路打下坚实基础!