我想覆盖DefaultItemAnimator,但能够将项目更改的动画(通过对notifyItemChanged的调用)设置为我自己的动画,我试图研究这个并且我查看了文档,但似乎你只能设置动画的持续时间。请帮忙
答案 0 :(得分:0)
来自DefaultItemAnimator类文档:
/**
* This implementation of {@link com.twotoasters.android.support.v7.widget.RecyclerView.ItemAnimator} provides basic
* animations on remove, add, and move events that happen to the items in
* a RecyclerView. RecyclerView uses a DefaultItemAnimator by default.
*
* @see com.twotoasters.android.support.v7.widget.RecyclerView#setItemAnimator(com.twotoasters.android.support.v7.widget.RecyclerView.ItemAnimator)
*/
通过覆盖animateRemobeImpl()
,animateAddImpl()
和animateMoveImpl()
方法,可以轻松完成自定义删除,添加或移动动画。但是,此类没有实现更改动画。
一个可能的解决方案是子类DefaultItemAnimator
并创建与更改动画相关的实例变量,使用这些变量的方式与删除,添加和移动变量相同,如:
private ArrayList<ViewHolder> mPendingChanges = new ArrayList<ViewHolder>();
private ArrayList<ViewHolder> mChangeAnimations = new ArrayList<ViewHolder>();