如何使用Glide将图像放入ImageView [英] How to fit Image into ImageView using Glide

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

问题描述

我关心的是如何使用 android:scaleType ="fitXY" 将图像适合使用 Glide 的图像.

My concern is how to fit image using android:scaleType="fitXY" into image using Glide.

我的 ImageView

<ImageView
    android:id="@+id/img_pager"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:scaleType="fitXY" />

使用 Glide 这样加载图片

Glide.with(context).load(url).placeholder(R.drawable.default_image).into(img);

但是图像没有适合 ImageView ,它在图像的两边都显示了空间,如屏幕所示,我需要它 fitXY

but image is not getting fit into ImageView it show space on image either side as shown in screen I need it fitXY

推荐答案

您可以使用 centerCrop() fitCenter()方法:

Glide.with(context)
     .load(url)
     .centerCrop()
     .placeholder(R.drawable.default_image)
     .into(img)

Glide.with(context)
     .load(url)
     .fitCenter()
     .placeholder(R.drawable.default_image)
     .into(img)

您还可以在以下位置找到更多信息: https://futurestud.io/tutorials/滑行图像调整大小缩放比例

You can also find more information at: https://futurestud.io/tutorials/glide-image-resizing-scaling

这篇关于如何使用Glide将图像放入ImageView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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