将表格行添加到表格布局时出现问题

发布于 2024-12-18 05:53:12 字数 1683 浏览 2 评论 0原文

我有以下代码:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

﹏雨一样淡蓝的深情 2024-12-25 05:53:12

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:

setContentView(ll);
把人绕傻吧 2024-12-25 05:53:12

沿着同一条线:tipsTable似乎是你的顶视图所以尝试setContentView(tipsTable)

along the same line: tipsTable seems to be your top view so try setContentView(tipsTable)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文