2011-03-11 71 views

回答

5

尝试这样:

TableLayout table = new TableLayout(this); 
    for (int i = 0; i < mRows; i++) { 

     TableRow tr = new TableRow(mContext); 
     tr.setLayoutParams(new TableRow.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); 

     for (int j = 0; j < mCols; j++) { 

      ImageView view = new ImageView(this); 
      view.setImageResource(R.drawable.star_on) 
      tr.addView(view); 
     } 
     table.addView(tr); 
    } 

这个程序生成整个表/格。你可以看到它如何实例化ImageView并设置图像。

+0

你如何设置图片浏览宽度和高度?我想让他们32 * 32,但我不能。怎么做呢? – 2012-05-27 22:47:04

相关问题