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
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,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));
}
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
发布评论
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
我敢打赌,你的 TableView 位于 LinearLayout 或不会溢出可用屏幕的东西中 - 因此最后一个视图会缩小以容纳所有内容 - 也许......你能确保你的 TableView 位于 ScrollView 中并且看看是否会发生这种情况?
-塞尔坎
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