简体   繁体   English

在图库中进行Android图像缩放

[英]Android image scaling in the Gallery

I have two images in a Gallery view. 我在Gallery视图中有两个图像。 First I add a 80x80 image, and then a bigger one (400x400). 首先,我添加一个80x80的图像,然后添加一个更大的图像(400x400)。 I want both images to be displayed as 80x80 to match the size of the first image. 我希望两个图像都显示为80x80以匹配第一个图像的大小。

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. 大图像显示为400x80,并且没有缩放:只有中心切片可见。

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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM