Android 以编程方式将ImageView添加到tableLayout
我有一个位图图像列表,如何以编程方式将此位图添加到tableLayoutAndroid 以编程方式将ImageView添加到tableLayout,android,android-layout,Android,Android Layout,我有一个位图图像列表,如何以编程方式将此位图添加到tableLayout 谢谢。试试这样: TableLayout table = new TableLayout(this); for (int i = 0; i < mRows; i++) { TableRow tr = new TableRow(mContext); tr.setLayoutParams(new TableRow.LayoutParams(LayoutParams.FIL
谢谢。试试这样:
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);
}
TableLayout table=新的TableLayout(此);
对于(int i=0;i
这将以编程方式生成整个表/网格。您可以看到它是如何实例化ImageView和设置图像的。尝试以下操作:
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);
}
TableLayout table=新的TableLayout(此);
对于(int i=0;i
这将以编程方式生成整个表/网格。您可以看到它如何实例化ImageView并设置图像。如何设置ImageView的宽度和高度?我想把它们做成32*32,但我做不到。怎么做?如何设置ImageView的宽度和高度?我想把它们做成32*32,但我做不到。怎么做?