8

我正在使用Glide 3.7.0RecyclerView。刷新时项目视图总是闪烁(调用notifyDataSetChanged)。为什么Glide在notifydatasetchanged时闪烁项目ImageView

这里是我的代码:

Glide 
    .with(context) 
    .load(filepath) 
    .diskCacheStrategy(DiskCacheStrategy.NONE) 
    .skipMemoryCache(true) 
    .dontAnimate() 
    .into(imageview); 

当我不使用缓存,ImageView有当notifyDataSetChanged方法被称为零位图和滑翔尚未完成加载位图。

如果我使用下面的代码:

Glide 
    .with(context) 
    .load(filepath) 
    .dontAnimate() 
    .into(imageview); 

然后该项目ImageView不眨眼了(使用高速缓存)。

我要动态地更新项目视图,所以我禁止滑行缓存。

是否有任何解决方案来解决这个闪烁的错误?

非常感谢!

回答

17

经过多次尝试,只需使用SimpleTarget解决了我的问题 谢谢!

Glide 
.with(context) 
.load(filepath) 
.asBitmap() 
.diskCacheStrategy(DiskCacheStrategy.NONE) 
.skipMemoryCache(true) 
.dontAnimate() 
.into(new SimpleTarget<Bitmap>() { 

      @Override 
      public void onResourceReady(Bitmap arg0, GlideAnimation<? super Bitmap> arg1) { 
       // TODO Auto-generated method stub 
       holder.mItemView.setImageBitmap(arg0); 
      } 
     }); 
0

更新滑翔从3版本4和setSupportsChangeAnimations(false)RecyclerView解决的问题对我来说

RecyclerView.ItemAnimator animator = recyclerView.getItemAnimator(); 
if (animator instanceof SimpleItemAnimator) { 
    ((SimpleItemAnimator) animator).setSupportsChangeAnimations(false); 
} 
0

在我的情况,我用我的imageView定义维度解决了问题。

<ImageView 
     android:id="@+id/poster_imageview" 
     android:layout_width="130dp" 
     android:layout_height="183dp" 
     android:adjustViewBounds="true" 
     android:scaleType="centerCrop" 
     android:src="@drawable/placeholder" />