I apply equal fields to mine RecyclerViewusing GridLayoutManager, overriding the method getItemOffsets()(see my code below).
However, when an object is deleted from the adapter, the delete animation is called without offsets. Thus, the anomaly begins in a different position than the object to be removed.
I tried to get the position through getSpanIndex(position), but the position ( parent.getChildAdapterPosition(view)) returns NO_POSITION, since the object is already removed from the adapter when called getItemOffsets().
Is there any way to get offsets in my case?
@Override
public void getItemOffsets(Rect outRect, View view,
RecyclerView parent, RecyclerView.State state) {
GridLayoutManager mgr = parent.getLayoutManager();
int position = parent.getChildAdapterPosition(view);
if (position == RecyclerView.NO_POSITION) {
return;
}
int spanCount = mgr.getSpanCount();
int spanSize = mgr.getSpanSizeLookup().getSpanSize(position);
int spanIndex = mgr.getSpanSizeLookup().getSpanIndex(position, spanCount);
if (spanIndex == spanCount-1) {
left = space / 2;
right = space;
} else if (spanIndex == 0) {
left = space;
right = space / 2;
} else {
left = space / 2;
right = space / 2;
}
outRect.set(left, top, right, bottom);
}
source
share