0
它只顯示1列。我想在tableRow中動態添加2列而不使用另一個for循環。它只顯示1列。我想在tableRow中動態添加2列而不使用另一個for循環。動態設置表格列爲2
**for (int j = 0; j <= arrtype.size() - 1; j++) {
row = new TableRow(this);
TableRow.LayoutParams trParams = (new TableRow.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
String arrnameHolder = arrname.get(j);
int imgId = getResources().getIdentifier(arrimage.get(j),
"drawable", "com.package");
RelativeLayout rl = new RelativeLayout(this);
RelativeLayout.LayoutParams rlParams = (new RelativeLayout.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
rlParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
img = new ImageView(this);
img.setLayoutParams(new TableRow.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
img.setPadding(10, 10, 10, 10);
img.setImageResource(imgId);
tv = new TextView(this);
tv.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT));
tv.setText(arrnameHolder);
tv.setTextColor(Color.WHITE);
// tv.setBackgroundColor(Color.parseColor("#7000"));
tv.setLayoutParams(rlParams);
tv.setBackgroundColor(color.background_dark);
tv.setTypeface(Typeface.DEFAULT_BOLD);
tv.setTextAppearance(getApplicationContext(),
android.R.style.TextAppearance_Large);
tv.setGravity(Gravity.CENTER);
tv.setPadding(10, 10, 10, 10);
rl.addView(img);
rl.addView(tv);
row.addView(rl);
table.addView(row);
}
scroll.addView(table);
layout.addView(scroll, scrollParam);
}**
做好@pallvi :) – SagarPPanchal 2013-05-13 12:07:58