开发者

Android image scaling in the Gallery

I开发者_如何学C have two images in a Gallery view. First I add a 80x80 image, and then a bigger one (400x400). I want both images to be displayed as 80x80 to match the size of the first image.

If I hardcode the size

image.setLayoutParams(new Gallery.LayoutParams(80, 80));
image.setScaleType(ImageView.ScaleType.CENTER_INSIDE);

all goes OK. But if I try to evade the hardcoding in case that the first image will be changed

image.setLayoutParams(new Gallery.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT));
image.setScaleType(ImageView.ScaleType.CENTER_INSIDE);

the big image is displayed as 400x80, and is not scaled: only the central slice of it is visible.

How can I make all the images in the Gallery to be scaled to match the size of the first added image without specifying that size directly?


Try with

image.setLayoutParams(new Gallery.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
image.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜