要禁止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的復用效果。