今天在向一个LinearLayout中动态添加一个TableLayout时,发现数据都正确,但是无论如何也显示不了。
后来发现是创建TableRow时,使用的布局参数错误了。
正确的创建参数如下
TableRow tr = new TableRow(context);
tr.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
如果需要让每行中的数据自动扩展,需要在向TableLayout添加完毕TableRows后,调用
tableLayout.setShrinkAllColumns(true);
本文介绍了如何解决在LinearLayout中动态添加TableLayout时显示不正常的问题。通过调整TableRow的布局参数和使用tableLayout.setShrinkAllColumns(true)方法,使得表格能够正确地显示并且内容能够自动扩展。
767

被折叠的 条评论
为什么被折叠?



