实际上用过TableLayout来作表格的人估计都碰到过,TableLayout有根据cell内容长度自动扩展的特点(要保证表格不变形,只能自己断行),如果cell合并,当合并cell太长时,自动扩展所在列的宽度,而不是根据合并后的列宽度来扩展,例子如下:
<screen title="TableLayout Demo">
<scrollpane scrollbar="both">
<container style="layout:tablelayout;gap:1 1;border:1 1 1 1;border-color:red;bg-color:red;font-size:large">
<text class="child1" style="min-size:30 0">姓名</text>
<text class="child1" style="min-size:50 0">部门</text><break/>
<text class="child1" style="span:2 1">我们是更加重视下拉</text>
</container>
</scrollpane>
<screenfirstmenu onAction="back">Back</screenfirstmenu>
<screenSecondMenu onAction="exit">Exit</screenSecondMenu>
</screen>
第二行采用合并单元格,结果第一列被迫扩展到必须包含合并cell文字的长度,效果如下图:
实际上在计算每列最小宽度时,作者偷了个懒,直接用所在列中最大长度的widget作为列宽度,而没有计算它合并的列,虽然实际上它确实对合并列做了一些处理.有兴趣的人可以看看它的align函数,这个函数可不是对齐,是计算每一列宽度
/**
* shappycom
* @param first 链表
* @param values 返回值(width/height)
* @param weights
* @param horizontal
* @param fullSize 减去边界和间隔后可用的长度
*/
private static final void align(Metrics first, int[] values, int[] weights, boolean horizontal, int fullSize) {
for (int size = 1, next = 0; size != 0; size = next, next = 0) {
for (Metrics metrics = first; metrics != null; metrics = metrics.next) {
Span span = metrics.widget.getSpan();
int orientedSpan = horizontal ? span.colspan : span.rowspan;
if (orientedSpan == size) {
int value;
if (weights != null) {
value = horizontal ? metrics.width : metrics.height;
} else {
Weight weight = metrics.widget.getWeight();
value = horizontal ? weight.weightx : weight.weighty;
}
int index = horizontal ? metrics.x : metrics.y;
if (weights != null && weights[index] != 0) {
value = MathFP.toInt(MathFP.mul(weights[index], MathFP.toFP(fullSize)));
}
values[index] = Math.max(values[index], value);
} else if ((orientedSpan > size) && ((next == 0) || (next > orientedSpan))) {
next = orientedSpan;
}
}
}
}
修改后效果图:
- 大小: 2.8 KB
- 大小: 2.3 KB
分享到:
相关推荐
java TableLayout布局
android中利用tablelayout实现表格效果
安卓 tablelayout布局实例..欢迎下载学习
TableLayout实现gridview嵌套gridview效果.md
andorid tablelayout实例 疯狂Android讲义
利用TableLayout自定义可点击表格
018集-TableLayout视频教程,讲解比较生动详细。
TableLayout的基本用法,选项卡
TableLayout,实现动态添加和删除行,判断行中的数据是否含有空值,可以手动地输入数据,也可以选择数据添加在表格中,并实现统计表格中的数据。
android 利用TableLayout自动生成表格
TableLayout 简单程序,但不常用的话容易忘记。特此发布,以备不时之需
TableLayout 简单程序,但不常用的话容易忘记。特此发布,以备不时之需
TableLayout+ViewPager+Fragment原生高级控件开发的一个可滑动的标题栏索引
Android使用TableLayout动态布局实例: http://blog.csdn.net/lk_blog/article/details/7436380
看到很多在安桌上做表格的例子,总感觉不太理想,所以自己做了一个,感觉比较好用,供参考。 (图片在哪儿上传?)
TableLayout 简单程序,但不常用的话容易忘记。特此发布,以备不时之需
最小包,不含example
TableLayout 简单程序,但不常用的话容易忘记。特此发布,以备不时之需
本资源是java tablelayout 资源包,希望能对您有所帮助。
用TableLayout实现九宫格参差不齐的排版用TableLayout实现九宫格参差不齐的排版