我一直在尝试为一组对话中的每个项目动态添加TableRows,但这些行没有显示出来。单步执行调试器时,我可以看到TableLayout上的子项数量增加,但之后都没有显示。
向TableLayout对话框添加行
List<Dialogue> content = post.getDialogue();
for (int i = 0; i < content.size(); i++) {
Dialogue d = content.get(i);
TableRow tr = (TableRow) layoutInflater.inflate(R.layout.chat_post_dialogue_include, dialogue, false);
tr.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
TextView label = (TextView) tr.findViewById(R.id.label);
label.setText(d.getLabel());
TextView dialogueLine = (TextView) tr.findViewById(R.id.dialogue_line);
dialogueLine.setText(d.getPhrase());
dialogue.addView(tr);
}
包含TableLayout的布局
<TextView
android:id="@+id/title"
style="@style/title" />
<TableLayout
android:id="@+id/dialogue"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@id/title" />
TableRow布局
<TextView
android:id="@+id/label"
android:gravity="top" />
<TextView
android:id="@+id/dialogue_line" />
答案 0 :(得分:0)
尝试使用
tr.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT,TableRow.LayoutParams.FILL_PARENT));
而不是!!