简体   繁体   中英

Glide rounded corner on notifydatasetchanged() is lost and becoming square

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);

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);

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.

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM