可以尝试使用 DiffUtil.DiffResult.dispatchUpdatesTo(ListUpdateCallback),实现自定义 ListUpdateCallback
例子:
private class CustomListUpdateCallback(val adapter: RecyclerView.Adapter<*>) : ListUpdateCallback {
override fun onChanged(position: Int, count: Int, payload: Any?) {
adapter.notifyItemRangeChanged(position + 1, count, payload)
}
override fun onMoved(fromPosition: Int, toPosition: Int) {
adapter.notifyItemMoved(fromPosition + 1, toPosition + 1)
}
override fun onInserted(position: Int, count: Int) {
adapter.notifyItemRangeInserted(position + 1, count)
}
override fun onRemoved(position: Int, count: Int) {
adapter.notifyItemRangeRemoved(position + 1, count)
}
}