动态添加的 TableRows 在 TableLayout 中不可见
我一直在尝试为一组对话中的每个项目动态添加 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" />
表行布局
<TextView
android:id="@+id/label"
android:gravity="top" />
<TextView
android:id="@+id/dialogue_line" />
I've been trying to dynamically add TableRows for each item in a set of dialogue, but the rows aren't showing up. When stepping through the debugger, I can see the number of children on the TableLayout increase, but afterward none show up.
Adding rows to TableLayout dialogue
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);
}
Layout containing 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 layout
<TextView
android:id="@+id/label"
android:gravity="top" />
<TextView
android:id="@+id/dialogue_line" />
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用
tr.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.FILL_PARENT));
反而 !!
Try using
tr.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.FILL_PARENT));
instead !!