viewHolders) {
613 | for (int i = viewHolders.size() - 1; i >= 0; i--) {
614 | ViewCompat.animate(viewHolders.get(i).itemView).cancel();
615 | }
616 | }
617 |
618 | /**
619 | * {@inheritDoc}
620 | *
621 | * If the payload list is not empty, BaseItemAnimator returns true.
622 | * When this is the case:
623 | *
624 | * If you override {@link #animateChange(ViewHolder, ViewHolder, int, int, int, int)}, both
625 | * ViewHolder arguments will be the same instance.
626 | *
627 | *
628 | * If you are not overriding {@link #animateChange(ViewHolder, ViewHolder, int, int, int, int)},
629 | * then BaseItemAnimator will call {@link #animateMove(ViewHolder, int, int, int, int)} and
630 | * run a move animation instead.
631 | *
632 | *
633 | */
634 | @Override
635 | public boolean canReuseUpdatedViewHolder(@NonNull ViewHolder viewHolder,
636 | @NonNull List payloads) {
637 | return !payloads.isEmpty() || super.canReuseUpdatedViewHolder(viewHolder, payloads);
638 | }
639 |
640 | private static class VpaListenerAdapter implements ViewPropertyAnimatorListener {
641 | VpaListenerAdapter() {
642 | }
643 |
644 | @Override
645 | public void onAnimationStart(View view) {}
646 |
647 | @Override
648 | public void onAnimationEnd(View view) {}
649 |
650 | @Override
651 | public void onAnimationCancel(View view) {}
652 | }
653 | /**
654 | * 执行移除动画
655 | * @param holder 被移除的ViewHolder
656 | * @param animator 被移动的ViewHolder对应动画对象
657 | */
658 | public abstract void setRemoveAnimation(ViewHolder holder,ViewPropertyAnimatorCompat animator);
659 | /**
660 | * 执行移除动画结束,执行还原,因为该ViewHolder会被复用
661 | * @param holder 被移除的ViewHolder
662 | */
663 | public abstract void removeAnimationEnd(ViewHolder holder);
664 | /**
665 | * 执行添加动画初始化 这里设置透明为0添加时就会有渐变效果当然你可以在执行动画代码之前执行
666 | * @param holder 添加的ViewHolder
667 | */
668 | public abstract void addAnimationInit(ViewHolder holder);
669 | /**
670 | * 执行添加动画
671 | * @param holder 添加的ViewHolder
672 | * @param animator 添加的ViewHolder对应动画对象
673 | */
674 | public abstract void setAddAnimation(ViewHolder holder,ViewPropertyAnimatorCompat animator);
675 | /**
676 | * 取消添加还原状态以复用
677 | * @param holder 添加的ViewHolder
678 | */
679 | public abstract void addAnimationCancel(ViewHolder holder);
680 | /**
681 | * 更新时旧的ViewHolder动画
682 | * @param holder 旧的ViewHolder
683 | * @param animator ViewHolder对应动画对象
684 | */
685 | public abstract void setOldChangeAnimation(ViewHolder holder,ViewPropertyAnimatorCompat animator);
686 | /**
687 | * 更新时旧的ViewHolder动画结束,执行还原
688 | * @param holder
689 | */
690 | public abstract void oldChangeAnimationEnd(ViewHolder holder);
691 | /**
692 | * 更新时新的ViewHolder初始化
693 | * @param holder 更新时新的ViewHolder
694 | */
695 | public abstract void newChangeAnimationInit(ViewHolder holder);
696 | /**
697 | * 更新时新的ViewHolder动画
698 | * @param holder 新的ViewHolder
699 | * @param animator ViewHolder对应动画对象
700 | */
701 | public abstract void setNewChangeAnimation(ViewHolder holder,ViewPropertyAnimatorCompat animator);
702 | /**
703 | * 更新时新的ViewHolder动画结束,执行还原
704 | * @param holder
705 | */
706 | public abstract void newChangeAnimationEnd(ViewHolder holder);
707 | }
708 |
--------------------------------------------------------------------------------