【问题标题】:Glide RoundedCornersTransformation not making any changes if scaleType is centerCrop如果 scaleType 为 centerCrop,则 Glide RoundedCornersTransformation 不会进行任何更改
【发布时间】:2017-11-21 06:59:19
【问题描述】:

我正在使用 Glide 4.3.0wasabeef/glide-transformations 在图像视图的左下角和右下角添加圆角半径。图像已加载,但未应用转换,我看不到角落有任何变化。

这是我的 Glide 转换:

Glide.with(context)
    .load(message.imageUrl)
    .apply(bitmapTransform(new RoundedCornersTransformation(25, 0, RoundedCornersTransformation.CornerType.BOTTOM)))
    .into(aq.id(R.id.ivSingleImage).getImageView());

我的导入如下:

import com.bumptech.glide.Glide;
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
import static com.bumptech.glide.request.RequestOptions.bitmapTransform;

图像已加载,但未应用任何转换。这个实现是否正确?

我也试过CornerType.BOTTOM_LEFTCornerType.BOTTOM_RIGHT

编辑

我注意到这只发生在 scaleType 设置为 centerCrop 时。如果我从 XML 中删除它,它可以工作,但图像的左侧和右侧有 2 个大空格:

<ImageView
     android:id="@+id/ivSingleImage"
     android:layout_width="match_parent"
     android:layout_height="100dp"
     android:layout_marginRight="5dp"
     android:layout_weight="1"
     android:background="@color/white"
     android:scaleType="centerCrop" <!--Removing this works. But leaves two spaces on left and right sides-->
     android:layout_marginEnd="5dp" />

参考更新^,我怎样才能有图像centerCrop并且仍然有一个圆角变换?

【问题讨论】:

  • 你能添加一张你已经完成的截图吗?
  • 为什么你将背景设置为白色,高度设置为 100 dp,只需尝试使用 wrap_content 作为宽度和高度,没有背景
  • @Meenal 已解决。发布答案

标签: android android-glide


【解决方案1】:

找到了解决办法。解决方案使用我在问题中提到的 glide-transformations 库中的 MultiTransformationCenterCrop 转换。

解决方案如下:

MultiTransformation multiLeft = new MultiTransformation(
     new CenterCrop(),
     new RoundedCornersTransformation(25, 0, RoundedCornersTransformation.CornerType.BOTTOM_LEFT));

Glide.with(context)
     .load(message.imageUrl)
     .apply(bitmapTransform(multiLeft))
     .into(aq.id(R.id.ivSingleImage).getImageView());

在 XML 的 scaleType 属性中使用 centerCrop 不适用于 Glide 库转换。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-07-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-13
    • 1970-01-01
    • 2021-12-11
    • 2018-08-25
    相关资源
    最近更新 更多