【发布时间】:2017-06-01 00:30:52
【问题描述】:
我正在使用 RecyclerView。将项目添加到 RecyclerView 后,我需要调用:
notifyItemRangeInserted(int positionStart, int itemCount);
但是,这显示了一种“向下滑动”动画。有没有办法可以禁用这个动画?
谢谢。
【问题讨论】:
标签: android android-recyclerview android-animation
我正在使用 RecyclerView。将项目添加到 RecyclerView 后,我需要调用:
notifyItemRangeInserted(int positionStart, int itemCount);
但是,这显示了一种“向下滑动”动画。有没有办法可以禁用这个动画?
谢谢。
【问题讨论】:
标签: android android-recyclerview android-animation
尝试清除RecyclerView item animator
recyclerView.setItemAnimator(null);
如果需要,您可以在之后重新启用动画。
recyclerView.setItemAnimator(null);
notifyItemRangeInserted(int positionStart, int itemCount);
recyclerView.setItemAnimator(new DefaultItemAnimator());
【讨论】:
您也可以像这样在 xml 布局文件中使用数据绑定:
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/my_recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:itemAnimator="@{null}" />
这是可能的,因为 RecyclerView 有一个名为 setItemAnimator 的公共函数!
【讨论】: