【发布时间】:2013-12-10 23:55:56
【问题描述】:
我在 android 中将 tablerows 添加到表格布局时遇到了一点问题。
这是我的代码:
int z = 0;
for(String detail: details){
TableRow tr = new TableRow(this);
tr.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
//odd / even
if(z%2 == 0)
tr.setBackgroundColor(Color.parseColor("#F5F5F5"));
//set detail text
TextView detailText = new TextView(this);
RelativeLayout.LayoutParams dtlp = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
detailText.setTextSize(16.0f);
detailText.setTextColor(Color.parseColor("#333333"));
detailText.setPadding(20, 10, 20, 10);
detailText.setLayoutParams(dtlp);
detailText.setText(detail);
tr.addView(detailText);
detailsTable.addView(tr);
++z;
}
我不知道问题出在哪里。正在设置详细文本视图,但表格行不会显示。
【问题讨论】:
-
上面的代码一切正常,你必须使用 LayoutParams,也试试这个 detailsTable.addView(tr, new TableLayout.LayoutParams(...,....) )
-
检查 YOUR_LAYOUT.xml 中的 TableLayout 高度和宽度,因为您已将 TableRow 宽度设置为 MATCH_PARENT 更改它到 WRAP_CONTENT。
标签: android android-tablelayout