ImageView允许缩小,但不能缩小

时间:2017-01-13 12:45:04

标签: android imageview image-scaling

如何缩小图像并适合ImageView,但避免向上缩放?

使用Glide解决,添加

...
.transform(new FitCenter(context) {
    @Override
    protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) {
        if (toTransform.getHeight() > outHeight || toTransform.getWidth() > outWidth)
            return super.transform(pool, toTransform, outWidth, outHeight);
        else
            return toTransform;
    }
})
...
目标android:scaleType="center"中的

ImageView

似乎没有办法只使用ImageView属性来获得这样的行为:(

1 个答案:

答案 0 :(得分:0)

您可以将Picasso库与参数.onlyScaleDown()

一起使用
Picasso  
    .with(context)
    .load(imageURI)
    .resize(600, 800) // or better use fit()
    .onlyScaleDown() // the image will only be resized if it's bigger than 6000x2000 pixels.
    .into(imageViewResizeScaleDown);

https://futurestud.io/tutorials/picasso-image-resizing-scaling-and-fit