关闭recyclerview动画
recyclerView.getItemAnimator().setAddDuration(0);
recyclerView.getItemAnimator().setChangeDuration(0);
recyclerView.getItemAnimator().setMoveDuration(0);
recyclerView.getItemAnimator().setRemoveDuration(0);
((SimpleItemAnimator)recyclerView.getItemAnimator()).setSupportsChangeAnimations(false);
此时可以解决item闪烁,但是item中图片仍然会闪烁,我的解决方法是给imageview设置tag
String imageUrl = bean.getProductPic();
if(ivLogo.getTag() == null){
Glide.with(AppContext.getmInstance())
.load(imageUrl) // 指定图片地址
.placeholder(R.drawable.musiczhanwei) // 未加载图片前的默认图
.error(R.drawable.musiczhanwei) // 加载失败显示的图片
.centerCrop() // 图片缩放类型
.addListener(new RequestListener<Drawable>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
return false;
}
@Override
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
ivLogo.setTag(imageUrl);
return false;
}
})
.diskCacheStrategy(DiskCacheStrategy.AUTOMATIC) //自动选择缓存策略
.priority(Priority.NORMAL) // 设置加载的优先级
.into(ivLogo);
}
网友评论