RecyclerView的性能优化

  1. 前言
    在项目中如果列表不断刷新而且数据很大,调用notifyDataSetChanged可能会导致屏幕卡顿。
  2. 使用
    通过如下方法替换直接调用notifyDataSetChanged,减少不必要的刷新, calculateDiff方法能够计算出那些Item需要刷新,那些不需要刷新。
        DiffUtil.DiffResult diffResult =
                DiffUtil.calculateDiff(new DiffCallBack(mData, list), true);
        diffResult.dispatchUpdatesTo(adapter);

你可能感兴趣的:(Android)