:TableLayout沒有縮水我試圖創建8X5圖像作爲一個表中的所有圖片
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TableLayout table = new TableLayout(this);
table.setStretchAllColumns(true);
table.setShrinkAllColumns(true);
for(int i = 0; i < 6; i++){
TableRow card = new TableRow(this);
card.setGravity(Gravity.CENTER);
for(int j = 0; j < 5; j++){
TableRow.LayoutParams paramsCard = new TableRow.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
paramsCard.setMargins(CARDS_MARGIN,CARDS_MARGIN,CARDS_MARGIN,CARDS_MARGIN);
ImageView imgCard = new ImageView(this);
imgCard.setImageResource(R.drawable.dos);
imgCard.setLayoutParams(paramsCard);
card.addView(imgCard);
}
table.addView(card);
}
setContentView(table);
table.setBackgroundDrawable(getResources().getDrawable(R.drawable.background));
}
但在最後一排,我得到的圖像更小,爲什麼呢?我明顯地設置了
table.setStretchAllColumns(true);
table.setShrinkAllColumns(true);
http://dl.dropbox.com/u/3340490/device-2011-10-01-002223.png
如果從xml文件加載該佈局,會發生同樣的事情嗎? –
我需要以編程方式進行。你的意思是如果我膨脹TableLayout? – Dayerman
是的,因爲通過代碼完全創建佈局有時會產生奇怪的結果 –