【问题标题】:issue adding table row to table layout将表格行添加到表格布局的问题
【发布时间】:2012-10-12 09:54:19
【问题描述】:

我有以下代码:

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 的行。这是为什么呢?

【问题讨论】:

    标签: java android tablelayout tablerow


    【解决方案1】:

    你不会在任何地方打电话给setContentView()。您创建此布局但从未将其分配给活动。我认为你想要做的是在你设置完所有布局之后:

    setContentView(ll);
    

    【讨论】:

      【解决方案2】:

      沿着同一条线:tipsTable 似乎是您的顶视图,因此请尝试 setContentView(tipsTable)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多