【问题标题】:What is the difference between centerCrop and optionalCenterCrop in Glide?Glide 中的 centerCrop 和 optionalCenterCrop 有什么区别?
【发布时间】:2021-10-28 13:47:20
【问题描述】:

我正在构建一个 Android 应用程序,我想在其中使用 Glide 显示图像。

我能够找到名为centerCropoptionalCenterCrop 的方法,如下所示

Glide.with(imageView.context)
     .load(imageUrl)
     .placeholder(placeHolder)
     .optionalCenterCrop()
     .into(imageView)

我在上面的实现中看不到任何变化,但下面的实现给 imageView 带来了一些显着的变化。

Glide.with(imageView.context)
     .load(imageUrl)
     .placeholder(placeHolder)
     .centerCrop()
     .into(imageView)

我想了解使用optionalCenterCrop() 而不是centerCrop() 有什么影响

【问题讨论】:

    标签: android imageview android-glide


    【解决方案1】:

    optionalCenterCrop()centerCrop() 之间的区别在于 optionalCenterCrop() 将 centerCrop 应用于所有默认类型并忽略未知类型,而 centerCrop() 方法在使用未知类型时抛出异常。

    基本上区别在于optionalCenterCrop() 不会在未知类型上抛出异常,而centerCrop() 会抛出应该由您处理的异常。

    【讨论】:

    • 我不太确定未知类型。你能帮我理解它们吗?我知道几个:fitXY、fitCenter、centerInside 等。
    • 没有。 'type' 是指加载操作的资源类型,即 Bitmap、drawable 等。
    猜你喜欢
    • 1970-01-01
    • 2010-10-02
    • 2011-12-12
    • 2010-09-16
    • 2012-03-14
    • 2012-02-06
    • 2011-02-25
    • 2011-11-22
    • 2015-03-26
    相关资源
    最近更新 更多