2011-05-16 45 views
1

我試圖將ImageView添加到Java中的TableRow中,但它始終顯示爲空白。圖像似乎在那裏,但它完全是白色的。如何將ImageView添加到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); 

爲什麼它不工作?

+0

你添加了新行'TableLayout '? – 2red13 2011-05-16 15:13:34

回答

0

我想你忘記了兩招:

1)你已經忘記了setContentView(view);

2)你忘了添加TableRowTableLayout

相關問題