簡體   English   中英

在notifydatasetchanged() 上滑動圓角丟失並變成方形

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

我正在使用 glide 加載圖像 url 並應用圓角轉換。 它適用於 recyclerview 的首次設置。 稍后當我在分頁后調用notifydatasetchanged() ,它變成方形。 我錯過了什么?

Glide.with(mContext)
      .load(primary.getpSmallImage())
      .bitmapTransform(new RoundedCornersTransformation(mContext, 8, 0, RoundedCornersTransformation.CornerType.ALL))
      .placeholder(R.drawable.ic_ph_small)
      .into(thumbnailImage);

使用此 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);

如果在調用notifydatasetchanged()后出現問題,則不要使用它。 事實上,該方法會占用大量 CPU 資源並在 recyclerview 中重新創建每個項目,即使這些項目已經添加。

分頁時使用notifyItemInsertednotifyItemRangeInserted 它會讓你避免你的問題。

根本不要使用notifyDataSetChanged()方法進行分頁。 而是使用notifyItemInserted() DiffUtil是提高應用程序性能的更好選擇。

如果您在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();

我也有同樣的問題並以這種方式修復它

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM