Open weihansheng opened 5 years ago
I use the following Code in my RecyclerView.Adapter to remove an Item. If the current scroll-position is at the top, everything works fine.
If the scroll-position is somewhere in the middle of the List, the List automatically scrolls to the Top of the View.
How to avoid this behaviour?
notifyItemRemoved(position); if (position != dataList.size()) { notifyItemRangeChanged(position, dataList.size() - position); }
try this:
DiscreteScrollLayoutManager.java
@Override
public void onItemsRemoved(RecyclerView recyclerView, int positionStart, int itemCount) {
int newPosition = currentPosition;
if (recyclerViewProxy.getItemCount() == 0) {
newPosition = NO_POSITION;
} else if (currentPosition >= positionStart) {
//if (currentPosition < positionStart + itemCount) {
if (currentPosition < itemCount) {
//If currentPosition is in the removed items, then the new item became current
currentPosition = NO_POSITION;
}
newPosition = Math.max(0, currentPosition - itemCount);
}
onNewPosition(newPosition);
}
I use the following Code in my RecyclerView.Adapter to remove an Item. If the current scroll-position is at the top, everything works fine.
If the scroll-position is somewhere in the middle of the List, the List automatically scrolls to the Top of the View.
How to avoid this behaviour?
notifyItemRemoved(position); if (position != dataList.size()) { notifyItemRangeChanged(position, dataList.size() - position); }