要禁止RecyclerView的复用,可以通过以下方法实现:
@Override
public int getItemViewType(int position) {
return position;
}
recyclerView.setLayoutManager(new LinearLayoutManager(context) {
@Override
public boolean supportsPredictiveItemAnimations() {
return false;
}
@Override
public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) {
//禁止回收子View
setRecycleChildrenOnDetach(false);
super.onLayoutChildren(recycler, state);
}
});
通过以上方法就可以实现禁止RecyclerView的复用效果。