Huy Thang
Huy Thang

Reputation: 49

How to stop Glide loading Image over and over again when scrolling in RecyclerView?

I'm using Glide v3.8.0 (not v4) to load Image in to ImageView in an item of RecyclerView, and there is a bit problems: every time scroll the RecyclerView up or down, Glide load the Image into ImageView that already been loaded before, and the bad result is scroll is not smooth because it keep reload Image every time I scroll to, I don't want to reload an image that completely loaded. I have found some same questions but still have no right answer to this problem

This is my code to load image into RecyclerView item

    Glide.with(mContext).load(function.BitmapToByte(function.GetBitmap(currSong.getData())))
            .diskCacheStrategy(DiskCacheStrategy.ALL).error(R.drawable.noteicon).into(holder.coverimg);

Upvotes: 4

Views: 2582

Answers (2)

Yousef Elsayed
Yousef Elsayed

Reputation: 145

I had this problem and i fixed it using

recyclerview.setItemViewCacheSize(50);

This way not all old items will be recycled

Upvotes: 0

3bdoelnaggar
3bdoelnaggar

Reputation: 1139

Try load it by file name Use something like string varible so let glide know that the same image loaded before

Upvotes: 0

Related Questions