Reputation: 160
I'm loading image url using glide and applying rounded corner transformation. It works fine for first setup of recyclerview. Later when i call notifydatasetchanged()
after pagination it becomes square. What am I missing?
Glide.with(mContext)
.load(primary.getpSmallImage())
.bitmapTransform(new RoundedCornersTransformation(mContext, 8, 0, RoundedCornersTransformation.CornerType.ALL))
.placeholder(R.drawable.ic_ph_small)
.into(thumbnailImage);
Upvotes: 3
Views: 3002
Reputation: 3452
datalist.clear(); //clear old data before adddi
SampleAdapter adapter = (SampleAdapter) recyclerview.getAdapter();
recyclerview.setAdapter(null);
recyclerview.setAdapter(adapter);
datalist.addAll(resource.getData());//add new data
adapter.notifyDataSetChanged();
I also had the same problem and fixed it in this way
Upvotes: 0
Reputation: 1389
Don't use notifyDataSetChanged()
method for pagination at all. instead use notifyItemInserted()
. DiffUtil is a better choice for your apps performance.
If you're loading your image inside onBindViewHolder()
method this problem shouldn't happen.
Upvotes: 1
Reputation: 410
If the problem happens after calling notifydatasetchanged()
then don't use it. In fact, that method takes a lot of CPU resources and recreate every item in recyclerview even these items have been already added.
When paginating use notifyItemInserted
or notifyItemRangeInserted
. It'll allow you to avoid your problem.
Upvotes: 1
Reputation: 1802
Use this diskCacheStrategy Saves the media item after all transformations to cache.
Glide.with(mContext)
.load(primary.getpSmallImage())
.diskCacheStrategy(DiskCacheStrategy.RESULT)
.bitmapTransform(new RoundedCornersTransformation(mContext, 8, 0,
RoundedCornersTransformation.CornerType.ALL))
.placeholder(R.drawable.ic_ph_small)
.into(thumbnailImage);
Upvotes: 2