【问题标题】:Inifinite Scroll Recycleview's imageview flickering when scroll滚动时无限滚动Recyclerview imageview闪烁
【发布时间】:2018-10-19 12:42:13
【问题描述】:

我正在使用 Google 分页库显示来自服务器的图像。当我显示来自 Localhost 的图像时,它可以完美运行,但使用实时服务器时,它的图像会闪烁。我试图让 localhost 睡眠 2 秒以延迟响应,但 localhost 的图像没有闪烁。我的问题与image-flickering-while-scrolling-in-recyclerview 问题相同。但我没有使用 asynctask 所以不能使用它的答案。

Recyclerview 适配器。

public class ItemAdapter extends PagedListAdapter<Item, ItemAdapter.ItemViewHolder> {
private Context mCtx;

ItemAdapter( Context mCtx) {
    super(DIFF_CALLBACK);
    this.mCtx = mCtx;
}

@NonNull
@Override
public ItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
    View view = LayoutInflater.from(mCtx).inflate(R.layout.recyclerview_users, parent, false);
    return new ItemViewHolder(view);
}
private static DiffUtil.ItemCallback<Item> DIFF_CALLBACK =
        new DiffUtil.ItemCallback<Item>() {
            @Override
            public boolean areItemsTheSame(Item oldItem, Item newItem) {
                return oldItem.id == newItem.id;
            }

            @Override
            public boolean areContentsTheSame(Item oldItem, Item newItem) {
                return oldItem.equals(newItem);
            }
        };
@Override
public void onBindViewHolder(@NonNull ItemViewHolder viewHolder, int position) {
    Item item = getItem(position);
    final ItemViewHolder holder = (ItemViewHolder) viewHolder;
    holder.image_date.setText(item.getDate());


    GlideApp
            .with(mCtx)
            .asBitmap()
            .load(item.getThumb())
            .diskCacheStrategy(DiskCacheStrategy.ALL)
            .into(holder.imageview);
}


class ItemViewHolder extends RecyclerView.ViewHolder {

    TextView image_date, image_weight, imageHit;
    ImageView imageView, imageView2;
    ProgressBar progressBar;

    ItemViewHolder(View view) {
        super(view);

        image_date = itemView.findViewById(R.id.image_date);
        image_weight = itemView.findViewById(R.id.image_weight);
        imageHit = itemView.findViewById(R.id.hit);
        imageView = (ImageView) itemView.findViewById(R.id.thumb_image);
       imageView2 = itemView.findViewById(R.id.thumb_image2);
        progressBar = itemView.findViewById(R.id.progressBarThumb);
    }
}
}

我正在使用这种方法。 https://www.simplifiedcoding.net/android-paging-library-tutorial。 当我使用与此方法相同的代码时。它工作正常。当我更改代码作为我的使用时,就会出现问题。 P.S.-问题是数据加载时。加载数据后,它就可以正常工作了。

【问题讨论】:

  • 能否请您添加recyclerAdapter代码和代码以更新recyclerview中的值
  • @JinsonPaul 编辑了问题。
  • 不要滑行,而是使用此代码并重试 Picasso.with(context) .load(url) .resize(50, 50) // 您的首选尺寸 .centerCrop() .into(imageView)
  • @JinsonPaul 在过去的 3 个月里,我一直被这个问题困扰。尝试了很多解决方案。正在使用 onscroll 进行无限滚动。移动到分页库,认为它会解决问题。不知道罪魁祸首是 Glide。
  • @JinsonPaul 现在,它正在工作。将其发布为答案,我会接受。

标签: android android-recyclerview android-paging


【解决方案1】:

使用此代码代替滑行并重试

  Picasso.with(context) .load(url) .resize(50, 50) // Your preferred size 
  .centerCrop() 
  .into(imageView);

【讨论】:

    【解决方案2】:

    用毕加索代替 Glide。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-20
      • 1970-01-01
      • 2010-11-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多