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);
再次刷新不会出现闪烁了,圆角也有了!完美!