TableLayout的属性
2016-04-25 09:37
323 查看
自动扩展
有时我们一行可能只有一列,然后下面一行的列数大于一列。那要让特定的列数自动伸展,就得使用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));
相关文章推荐
- eclipse启动Tomcat正常,访问报错404
- 反射
- mybatis3.2.3+spring整合
- 致自己和万千正在踏入开发行业的朋友们
- redis性能问题排查
- synchronization in Linux kernel
- Block小结
- GCC中文手册
- AS项目添加RecyclerView-v7步骤
- HDU 5668 Circle (约瑟夫游戏,求解同余方程组)
- node.js 源码安装node.js
- ICTCLAS 汉语词性标注集
- 对已经add的文件不在跟踪
- Windows 10年度更新Anniversary Update预览版开始推送,版本号Build 14328
- 使用ltrace工具跟踪PHP库函数调用的方法
- jquery学习02(效果)
- CI MY_Controller &MY_Model
- [CareerCup] 17.7 English Phrase Describe Integer 英文单词表示数字
- 测量屏幕的宽高
- Tricks (四十一)—— 一 list 两用