【问题标题】:Glide - Is there a benefit of using .centerCrop() instead of android:scaleType="centerCrop" on my ImageView?Glide - 在我的 ImageView 上使用 .centerCrop() 而不是 android:scaleType="centerCrop" 有什么好处吗?
【发布时间】:2021-12-16 19:29:16
【问题描述】:

我正在使用 Glide 图像加载库将图像加载到我的 ImageView

Glide.with(this).load(url).into(imageView);

我在 github 页面上阅读了有关如何使用 Glide 的自述文件,我注意到在示例中他们使用方法 .centerCrop() 来裁剪图像。

Glide.with(this).load(url).centerCrop().into(imageView);

与仅在ImageView 中使用scaleType 属性相比,使用此方法有什么好处吗?

<ImageView
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:scaleType="centerCrop"

我在没有.centerCrop() 方法的情况下尝试了它,只使用了 xml 属性,它们看起来基本相同。 Glide 是否有某种底层优化,可以消耗更少的内存或使该方法成为更好的选择?

【问题讨论】:

    标签: android android-glide


    【解决方案1】:

    centerCrop 对内存使用没有任何影响,它只是缩放图像

    【讨论】:

    • 我只能说,如果你想在 app 中以编程方式进行 centerCrop ,请使用 glide 的 centerCrop ,否则 android:scaleType="centerCrop" 没有任何区别
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-12-25
    • 1970-01-01
    • 2018-08-25
    • 1970-01-01
    • 2023-03-15
    • 2020-07-27
    • 1970-01-01
    相关资源
    最近更新 更多