在 ImageView Android 中使用 Glide 调整图像大小 [英] Resize images with Glide in a ImageView Android

查看:44
本文介绍了在 ImageView Android 中使用 Glide 调整图像大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对android中图片的处理有很多疑问,希望你能解决一下.

I have a lot of doubts about the treatment of the images in android, and I was hoping to see if you could solve them.

此时我有一个图像,它占据 320 dp 高,match_parent 宽度,大约是屏幕的 60%.这张用 Glide 加载的图片,我个人在 1080 中的一些图片.

At this point I have an image that occupies 320 dp high, and match_parent width, which is around 60% of the screen. This image of the load with Glide, of some images in 1080 that I have personally.

我尝试制作 centroCrop 和 fitXY,但总是使图像变形.我所知道的第一种类型会剪切图像,但第二种类型适合某个尺寸,但它确实会使图像变形高或宽.

I tried to make centroCrop and fitXY, but always deform the images. The first type I know cuts the image, but the second one fits a size, but it does deform the image high or wide.

有什么办法可以用 Glide 插入它并按原样查看它吗?我需要在 ImageView 和 Glide 上接触哪些属性?

Is there any way, to insert it with Glide and see it as it is? What properties have I to touch on ImageView and which of Glide?

<ImageView
        android:id="@+id/img"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:nestedScrollingEnabled="false"
        app:layout_collapseMode="parallax"
        android:scaleType="fitXY"
        app:layout_scrollFlags="scroll|enterAlways" />

推荐答案

Override 必须在最新版本的 Glide 4.x 中通过 RequestOptions 访问.您可以通过 apply()

Override must be accessed via RequestOptions in the most recent version of Glide 4.x. You can add RequestOptions through apply()

Glide
    .with(context)
    .load(path)
    .apply(new RequestOptions().override(600, 200))
    .into(imageViewResizeCenterCrop);

这篇关于在 ImageView Android 中使用 Glide 调整图像大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆