TableLayout not shrink all images
I am trying to to create a table of 8x5 images as:
@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,CAR开发者_JAVA技巧DS_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));
}
But in the last row I get the images smaller, why? I apparently set
table.setStretchAllColumns(true);
table.setShrinkAllColumns(true);
http://dl.dropbox.com/u/3340490/device-2011-10-01-002223.png
I bet you, your TableView is in a LinearLayout or something which wouldn't overflow of the available screen - so the last views are shrunk to have everything fit in there - maybe... Can you make sure your TableView is in a ScrollView and see if this happens?
-serkan
If u have given the Margin or padding to the Outer Layout which is parent of the TableLayout, then set it. It will happend sometimes just because u have given some marginn and some padding to the Parent layout of the TableLayout. Hope it will help you. Thanks.
Eventually I use a LinearLayout with the weigths set to 1 to auto adjust to the screen size. TableLayout doesnt work very well at adjusting images.
精彩评论