简体   繁体   English

在notifydatasetchanged() 上滑动圆角丢失并变成方形

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

I'm loading image url using glide and applying rounded corner transformation.我正在使用 glide 加载图像 url 并应用圆角转换。 It works fine for first setup of recyclerview.它适用于 recyclerview 的首次设置。 Later when i call notifydatasetchanged() after pagination it becomes square.稍后当我在分页后调用notifydatasetchanged() ,它变成方形。 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.使用此 diskCacheStrategy 将所有转换后的媒体项保存到缓存。

  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.如果在调用notifydatasetchanged()后出现问题,则不要使用它。 In fact, that method takes a lot of CPU resources and recreate every item in recyclerview even these items have been already added.事实上,该方法会占用大量 CPU 资源并在 recyclerview 中重新创建每个项目,即使这些项目已经添加。

When paginating use notifyItemInserted or notifyItemRangeInserted .分页时使用notifyItemInsertednotifyItemRangeInserted It'll allow you to avoid your problem.它会让你避免你的问题。

Don't use notifyDataSetChanged() method for pagination at all.根本不要使用notifyDataSetChanged()方法进行分页。 instead use notifyItemInserted() .而是使用notifyItemInserted() DiffUtil is a better choice for your apps performance. DiffUtil是提高应用程序性能的更好选择。

If you're loading your image inside onBindViewHolder() method this problem shouldn't happen.如果您在onBindViewHolder()方法中加载图像, onBindViewHolder()不应发生此问题。

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我也有同样的问题并以这种方式修复它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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