TableLayout的属性
来源:互联网 发布:淘宝账号解封 编辑:程序博客网 时间:2024/05/22 01:54
自动扩展
有时我们一行可能只有一列,然后下面一行的列数大于一列。那要让特定的列数自动伸展,就得使用
android:strechColumns=”” 表示如果后面有剩下位置,则将各列都伸展,如果* 换成0,则表示第1列伸展,1表示第二列。
TableRow下控件属性:android:layout_span=”n” 表示该控件的占n列。两个结合在一起使用效果最好。
我的表格最多有两列,然后也有一列的。去掉其中一个属性都不能满足要求,无法自动伸展。图1为要求,图二为只去掉strechcolumns,图三为只去掉layout_span的。
动态添加TableRow
代码很简单。先new tablerow,再new需要添加到tablerow的控件,然后往控件添加内容,tableRow.addView(控件名),tableLayout.addView(tableRow)即可。注意的一点就是我一开始是使用同一个TextView添加到TableRow里的。然后一直报错说The specifed child already has a parent。其实就是说该TextView已经被添加到TableRow里了。不能被其他添加。这时如果使用TableRow.removeAllView就不会报错,但是之前添加的TextView没了。所以只能要几列new几个控件。
TableRow tableRow = new TableRow(this); TextView name = new TextView(this); TextView credit=new TextView(this); TextView grade=new TextView(this); TextView rank=new TextView(this); TextView gpa=new TextView(this); name.setSingleLine(false); name.setWidth(200); credit.setSingleLine(false); grade.setSingleLine(false); rank.setSingleLine(false); gpa.setSingleLine(false); tableRow.removeAllViews(); name.setText(g.getName()); tableRow.addView(name); credit.setText(g.getCredit()); tableRow.addView(credit); grade.setText(g.getScore()); tableRow.addView(grade); gpa.setText(g.getGpa()); tableRow.addView(gpa); rank.setText(g.getRank()); tableRow.addView(rank); tableLayout.addView(tableRow,new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
0 0
- TableLayout 属性的设置
- TableLayout的属性
- RelativeLayout、TableLayout的属性
- TableLayout经常用的属性
- TableLayout各个属性的作用
- TableLayout属性
- TableLayout属性
- TableLayout的常用属性及含义
- Tablelayout 属性详解
- Android TableLayout 属性含义
- TableLayout中的特殊属性
- TableLayout一些XMl属性
- android 控件TableLayout中合并单元格的属性
- android开发中TableLayout的一些属性介绍
- TableLayout的理解
- android 的tablelayout
- TableLayout的使用
- TableLayout的简单使用
- node.js 源码安装node.js
- 使用Git创建一个版本
- AS项目添加RecyclerView-v7步骤
- GCC中文手册
- 在XCode中使用TODO FIXME等标记
- TableLayout的属性
- 串珠子-Java
- 机房水题欢乐赛 2016-04-25 下午
- iOS:编译错误[__NSDictionaryM ....]: unrecognized selector sent to instance 0xa79e61
- log4j中的配置详解
- node.js node包管理器--npm
- eclipse配置apache tomcat运行时访问路径不需要项目名称
- Leetcode no. 15
- Ubuntu14.04下安装opencv3.0