RecyclerView列表中加载图片刷新闪烁问题

RecyclerView列表中加载图片刷新闪烁问题

由于只是一个问题,单独记录一下
经过多方对比查找,最终确定问题出现在glide加载图片时使用的圆角裁剪功能导致的,查看代码是由于自己写的裁剪代码,替换成官方的裁剪后刷新不会闪烁了,但是圆角又不见了,继续查看源码发现有这样一个方法

  /**
   * Applies the given {@link Transformation}s in the given order for
   * {@link Bitmap Bitmaps} to the default types ({@link Bitmap},
   * {@link android.graphics.drawable.BitmapDrawable}, and
   * {@link com.bumptech.glide.load.resource.gif.GifDrawable})
   * and throws an exception if asked to transform an unknown type.
   *
   * <p>This will override previous calls to {@link #dontTransform()}.
   *
   * @param transformations One or more {@link Transformation}s for {@link Bitmap}s.
   * @see #optionalTransform(Transformation)
   * @see #optionalTransform(Class, Transformation)
   */
  // Guaranteed to modify the current object by the isAutoCloneEnabledCheck.
  @SuppressWarnings({"unchecked", "varargs", "CheckResult"})
  @NonNull
  @CheckResult
  public RequestOptions transforms(@NonNull Transformation<Bitmap>... transformations) {
    return transform(new MultiTransformation<>(transformations), /*isRequired=*/ true);
  }

所以我们可以这样设置加载图片

            RequestOptions options = new RequestOptions()
                    .transforms(new CenterCrop(),new GlideRoundTransform(r,0))
//                    .placeholder(placeResId)
                    .error(placeResId)
                    .diskCacheStrategy(DiskCacheStrategy.DATA)
                    .dontAnimate();
            Glide.with(context).load(imgUrl).apply(options).into(iv);

再次刷新不会出现闪烁了,圆角也有了!完美!

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值