将表格行添加到表格布局时出现问题
我有以下代码:
HashMap<String, String> tip = venue.tips.get(j);
TableRow tr = new TableRow(this);
TableRow.LayoutParams tableRowParams =
new TableRow.LayoutParams
(TableRow.LayoutParams.FILL_PARENT,TableRow.LayoutParams.WRAP_CONTENT);
tr.setLayoutParams(tableRowParams);
LinearLayout ll = new LinearLayout(this);
ll.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
TextView tips = new TextView(this);
tips.setText(tip.get("text"));
Log.v("TIPS TEXT", tip.get("text"));
tips.setLayoutParams(new LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
ImageView avatar = new ImageView(this);
avatar.setImageBitmap(getBitmapFromURL(tip.get("photo")));
Log.v("PHOTO URL", tip.get("photo"));
avatar.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
ll.addView(tips);
ll.addView(avatar);
tr.addView(ll);
View v = new View(this);
v.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, 1));
v.setBackgroundColor(Color.rgb(51, 51, 51));
tipsTable.addView(tr,new TableLayout.LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
tipsTable.addView(v);
我认为我在设置布局时做错了,但现在的问题是我看不到添加到 TipsTable 中的行。这是为什么呢?
I have the following code:
HashMap<String, String> tip = venue.tips.get(j);
TableRow tr = new TableRow(this);
TableRow.LayoutParams tableRowParams =
new TableRow.LayoutParams
(TableRow.LayoutParams.FILL_PARENT,TableRow.LayoutParams.WRAP_CONTENT);
tr.setLayoutParams(tableRowParams);
LinearLayout ll = new LinearLayout(this);
ll.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
TextView tips = new TextView(this);
tips.setText(tip.get("text"));
Log.v("TIPS TEXT", tip.get("text"));
tips.setLayoutParams(new LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
ImageView avatar = new ImageView(this);
avatar.setImageBitmap(getBitmapFromURL(tip.get("photo")));
Log.v("PHOTO URL", tip.get("photo"));
avatar.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
ll.addView(tips);
ll.addView(avatar);
tr.addView(ll);
View v = new View(this);
v.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, 1));
v.setBackgroundColor(Color.rgb(51, 51, 51));
tipsTable.addView(tr,new TableLayout.LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
tipsTable.addView(v);
I think I did something wrong with setting up the layout, but the issue now is that I can't see the rows added to the tipsTable. Why is this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您没有调用 setContentView()< /a> 任何地方。您创建此布局但从未将其分配给活动。我认为你想要做的是在设置完所有布局之后:
You're not calling setContentView() anywhere. You create this layout but never assign it to the activity. I think what you want to do is after you've set up all your layout stuff:
沿着同一条线:tipsTable似乎是你的顶视图所以尝试setContentView(tipsTable)
along the same line: tipsTable seems to be your top view so try setContentView(tipsTable)