下面是调用不同的notify方法适配器执行的方法顺序如下:
对应上文
1、执行notifyAllData(),实际调用的是 notifyDataSetChanged 刷新全部,适配器执行方法如下
getItemCount: 6 getItemCount: 6 getItemCount: 6 getItemViewType: 0 onBindViewHolder:三个参数 onBindViewHolder:两个参数 getItemCount: 6 getItemViewType: 1 onBindViewHolder:三个参数 onBindViewHolder:两个参数 getItemCount: 6 getItemViewType: 2 onBindViewHolder:三个参数 onBindViewHolder:两个参数 getItemCount: 6 getItemViewType: 3 onBindViewHolder:三个参数 onBindViewHolder:两个参数 getItemCount: 6 getItemViewType: 4 onBindViewHolder:三个参数 onBindViewHolder:两个参数 getItemCount: 6 getItemViewType: 5 onCreateViewHolder: onBindViewHolder:三个参数 onBindViewHolder:两个参数 getItemCount: 6 getItemCount: 6 getItemViewType: 0 getItemCount: 6 getItemViewType: 1 getItemCount: 6 getItemViewType: 2 getItemCount: 6 getItemViewType: 3 getItemCount: 6 getItemViewType: 4 getItemCount: 6 getItemViewType: 5
2、执行notify_2(),实际调用的是 notifyItemChanged(2),适配器执行方法如下
getItemCount: 6 getItemCount: 6 getItemViewType: 0 getItemCount: 6 getItemViewType: 1 getItemCount: 6 getItemViewType: 2 onCreateViewHolder: onBindViewHolder:三个参数 onBindViewHolder:两个参数 getItemCount: 6 getItemViewType: 3 getItemCount: 6 getItemViewType: 4 getItemCount: 6 getItemViewType: 5 onCreateViewHolder: onBindViewHolder:三个参数 onBindViewHolder:两个参数 getItemCount: 6 getItemCount: 6 getItemViewType: 0 getItemCount: 6 getItemViewType: 1 getItemCount: 6 getItemViewType: 2 getItemCount: 6 getItemViewType: 3 getItemCount: 6 getItemViewType: 4 getItemCount: 6 getItemViewType: 5
3、执行notify_234(),实际调用的是 notifyItemRangeChanged(2, 3);,适配器执行方法如下
getItemCount: 6 getItemCount: 6 getItemViewType: 0 getItemCount: 6 getItemViewType: 1 getItemCount: 6 getItemViewType: 2 onCreateViewHolder: onBindViewHolder:三个参数 onBindViewHolder:两个参数 getItemCount: 6 getItemViewType: 3 onCreateViewHolder: onBindViewHolder:三个参数 onBindViewHolder:两个参数 getItemCount: 6 getItemViewType: 4 onCreateViewHolder: onBindViewHolder:三个参数 onBindViewHolder:两个参数 getItemCount: 6 getItemViewType: 5 onCreateViewHolder: onBindViewHolder:三个参数 onBindViewHolder:两个参数 getItemCount: 6 getItemCount: 6 getItemViewType: 0 getItemCount: 6 getItemViewType: 1 getItemCount: 6 getItemViewType: 2 getItemCount: 6 getItemViewType: 3 getItemCount: 6 getItemViewType: 4 getItemCount: 6 getItemViewType: 5
4、执行notifyPart_2(),实际调用的是 notifyItemChanged(2, “title”);,适配器执行方法如下
getItemCount: 6 getItemCount: 6 getItemViewType: 0 getItemCount: 6 getItemViewType: 1 getItemCount: 6 getItemViewType: 2 onBindViewHolder:三个参数 getItemCount: 6 getItemViewType: 3 getItemCount: 6 getItemViewType: 4 getItemCount: 6 getItemViewType: 5 onCreateViewHolder: onBindViewHolder:三个参数 onBindViewHolder:两个参数 getItemCount: 6 getItemCount: 6 getItemViewType: 0 getItemCount: 6 getItemViewType: 1 getItemCount: 6 getItemViewType: 2 getItemCount: 6 getItemViewType: 3 getItemCount: 6 getItemViewType: 4 getItemCount: 6 getItemViewType: 5
5、执行notifyPart_234(),实际调用的是notifyItemRangeChanged(2, 3, “content”);,适配器执行方法如下
getItemCount: 6 getItemCount: 6 getItemViewType: 0 getItemCount: 6 getItemViewType: 1 getItemCount: 6 getItemViewType: 2 onBindViewHolder:三个参数 getItemCount: 6 getItemViewType: 3 onBindViewHolder:三个参数 getItemCount: 6 getItemViewType: 4 onBindViewHolder:三个参数 getItemCount: 6 getItemViewType: 5 onCreateViewHolder: onBindViewHolder:三个参数 onBindViewHolder:两个参数 getItemCount: 6 getItemCount: 6 getItemViewType: 0 getItemCount: 6 getItemViewType: 1 getItemCount: 6 getItemViewType: 2 getItemCount: 6 getItemViewType: 3 getItemCount: 6 getItemViewType: 4 getItemCount: 6 getItemViewType: 5
6、执行insert_1_1(),实际调用的是notifyItemInserted(1);,适配器执行方法如下
getItemCount: 6 getItemCount: 6 getItemViewType: 0 getItemCount: 6 getItemViewType: 1 onCreateViewHolder: onBindViewHolder:三个参数 onBindViewHolder:两个参数 getItemCount: 6 getItemViewType: 2 getItemCount: 6 getItemViewType: 3 getItemCount: 6 getItemViewType: 4 getItemCount: 6 getItemViewType: 5 getItemCount: 6 getItemCount: 6 getItemViewType: 0 getItemCount: 6 getItemViewType: 1 getItemCount: 6 getItemViewType: 2 getItemCount: 6 getItemViewType: 3 getItemCount: 6 getItemViewType: 4 getItemCount: 6 getItemViewType: 5
7、执行insert_3_2(),实际调用的是notifyItemRangeInserted(3, 2);,适配器执行方法如下
getItemCount: 7 getItemCount: 7 getItemViewType: 0 getItemCount: 7 getItemViewType: 1 getItemCount: 7 getItemViewType: 2 getItemCount: 7 getItemViewType: 3 onCreateViewHolder: onBindViewHolder:三个参数 onBindViewHolder:两个参数 getItemCount: 7 getItemViewType: 4 onCreateViewHolder: onBindViewHolder:三个参数 onBindViewHolder:两个参数 getItemCount: 7 getItemViewType: 5 getItemCount: 7 getItemViewType: 6 getItemCount: 7 getItemCount: 7 getItemViewType: 0 getItemCount: 7 getItemViewType: 1 getItemCount: 7 getItemViewType: 2 getItemCount: 7 getItemViewType: 3 getItemCount: 7 getItemViewType: 4 getItemCount: 7 getItemViewType: 5 getItemCount: 7 getItemViewType: 6
7、执行move_2_4(),实际调用的是notifyItemMoved(2, 4);,适配器执行方法如下
getItemCount: 5 getItemCount: 5 getItemViewType: 0 getItemCount: 5 getItemViewType: 1 getItemCount: 5 getItemViewType: 2 getItemCount: 5 getItemViewType: 3 getItemCount: 5 getItemViewType: 4 getItemCount: 5 getItemCount: 5 getItemViewType: 0 getItemCount: 5 getItemViewType: 1 getItemCount: 5 getItemViewType: 2 getItemCount: 5 getItemViewType: 3 getItemCount: 5 getItemViewType: 4
8、执行remove2(),实际调用的是notifyItemRemoved(2);,适配器执行方法如下
getItemCount: 4 getItemCount: 4 getItemViewType: 0 getItemCount: 4 getItemViewType: 1 getItemCount: 4 getItemViewType: 2 getItemCount: 4 getItemViewType: 3 getItemCount: 4 getItemCount: 4 getItemViewType: 0 getItemCount: 4 getItemViewType: 1 getItemCount: 4 getItemViewType: 2 getItemCount: 4 getItemViewType: 3
9、执行remove234(),实际调用的是notifyItemRangeRemoved(2, 3);,适配器执行方法如下
getItemCount: 2 getItemCount: 2 getItemViewType: 0 getItemCount: 2 getItemViewType: 1 getItemCount: 2 getItemCount: 2 getItemViewType: 0 getItemCount: 2 getItemViewType: 1
RecyclerView的动画ItemAnimator:
ItemAnimator主要用于ReyclerView的item添加,移除,更新时的动画,ItemAnimator的直接子类是SimpleItemAnimator.
DefaultItemAnimator继承的是抽象类SimpleItemAnimator,SimpleItemAnimator主要对动画内部实现进行封装,通过抽象让我们只关注于更具体的操作。所以我们如果想实现一个自己的动画,那么我们就需要定义一个类,并且继承SimpleItemAnimator,然后去实现对应的抽象方法。
RecyclerView动画可以选择使用三方库
Github地址
https://github.com/wasabeef/recyclerview-animators