【问题标题】:How to add an ImageView to a TableRow in code如何在代码中将 ImageView 添加到 TableRow
【发布时间】:2013-09-08 17:55:21
【问题描述】:

我正在尝试将 ImageView 添加到 Java 中的 TableRow 中,但它始终显示为空白。图像似乎在那里,但它完全是白色的。

这是我的代码:

TableRow newRow = new TableRow(this);
newRow.setId(1);
LayoutParams lptr = new LayoutParams(
    LayoutParams.WRAP_CONTENT,
    LayoutParams.WRAP_CONTENT);
newRow.setLayoutParams(lptr);
newRow.setBackgroundColor(this.getResources().getColor(R.color.white));

ImageView pImg = new ImageView(this);
pImg.setImageDrawable(this.getResources().getDrawable(R.drawable.error));
newRow.addView(pImg);

为什么它不起作用?

【问题讨论】:

  • 您是否将新行添加到TableLayout

标签: android imageview drawable


【解决方案1】:

我想你忘记了两件事:

1) 你忘记了setContentView(view);

2) 您忘记将您的TableRow 添加到TableLayout

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-07
    • 1970-01-01
    相关资源
    最近更新 更多