我在代码中用位图更改了 imageview 源,但它不保持比例。它使用旧图像的尺寸。
我设置位图;
imageView.setImageBitmap(bitmap);
它拉伸(stretch)位图以适应旧图像资源的尺寸。我想保持位图比例。
最佳答案
查看 imageView ScaleTypes:http://developer.android.com/reference/android/widget/ImageView.ScaleType.html
CENTER Center the image in the view, but perform no scaling.
CENTER_CROP Scale the image uniformly (maintain the image's aspect ratio) so that both dimensions (width and height) of the image will be equal to or larger than the corresponding dimension of the view (minus padding).
CENTER_INSIDE Scale the image uniformly (maintain the image's aspect ratio) so that both dimensions (width and height) of the image will be equal to or less than the corresponding dimension of the view (minus padding).
FIT_CENTER Scale the image using CENTER.
FIT_END Scale the image using END.
FIT_START Scale the image using START.
FIT_XY Scale the image using FILL.
MATRIX Scale using the image matrix when drawing.
你想要 CENTER_CROP 或 CENTER_INSIDE 之类的东西
关于android - 保持位图比例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23885414/