如何缩放 ImageView 中的图像以使其“适合”
我想按以下方式缩放 ImageView 中的图像。 ImageView 有一些尺寸:宽度 (W) 和高度 (H)。我放入图像视图中的图像可能比宽x高更小或更大。我希望它能够缩放,同时保持纵横比以填充宽x高空间。
似乎最接近我想要的东西是 android:scaleType="centerInside",但我看到的是,如果图像小于 WxH,它将将该图像的小型未缩放版本放在中心ImageView (如文档所述),但我希望它将其缩放到“适合”,同时显示整个图像,并将其拉伸到容器的最大可能大小而不裁剪任何内容。换句话说,拉伸时保持纵横比,直到宽度或高度碰到容器 (ImageView) 的边缘。
这似乎是一件显而易见的事情,但我无法让它以这种方式工作!
I want to scale an image in an ImageView in the following way. The ImageView has some dimensions Width (W) and Height (H). The image I'm putting into the image view could be smaller or bigger than WxH. I want it to scale while preserving aspect ratio to fill WxH space.
It seems like the closest thing to what I want is android:scaleType="centerInside", but what I'm seeing is that if the image is smaller than WxH, it will put a small-unscaled version of that image in the center of the ImageView (like the documentation says), but I want it to scale it to "fit", while showing the entire image, and stretching it to the maximum possible size of the container without cropping anything. In other words, stretch preserving aspect ratio until either the width or the height bumps into the edge of the container (ImageView).
This seems like an obvious thing to want to do, but I can't get it to work this way!!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从 Android 文档...
其 XML 属性是...
From the Android docs...
The XML attribute for this is...