### Question:
GridLayoutManager extends LinearLayoutManager { public void setSpanSizeLookup(SpanSizeLookup spanSizeLookup) { mSpanSizeLookup = spanSizeLookup; } GridLayoutManager(Context context, AttributeSet attrs, int defStyleAttr,
                             int defStyleRes);  GridLayoutManager(Context context, int spanCount);  GridLayoutManager(Context context, int spanCount,
            @RecyclerView.Orientation int orientation, boolean reverseLayout); @Override void setStackFromEnd(boolean stackFromEnd); @Override int getRowCountForAccessibility(RecyclerView.Recycler recycler,
            RecyclerView.State state); @Override int getColumnCountForAccessibility(RecyclerView.Recycler recycler,
            RecyclerView.State state); @Override void onInitializeAccessibilityNodeInfoForItem(RecyclerView.Recycler recycler,
            RecyclerView.State state, View host, AccessibilityNodeInfoCompat info); @Override void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state); @Override void onLayoutCompleted(RecyclerView.State state); @Override void onItemsAdded(RecyclerView recyclerView, int positionStart, int itemCount); @Override void onItemsChanged(RecyclerView recyclerView); @Override void onItemsRemoved(RecyclerView recyclerView, int positionStart, int itemCount); @Override void onItemsUpdated(RecyclerView recyclerView, int positionStart, int itemCount,
            Object payload); @Override void onItemsMoved(RecyclerView recyclerView, int from, int to, int itemCount); @Override RecyclerView.LayoutParams generateDefaultLayoutParams(); @Override RecyclerView.LayoutParams generateLayoutParams(Context c, AttributeSet attrs); @Override RecyclerView.LayoutParams generateLayoutParams(ViewGroup.LayoutParams lp); @Override boolean checkLayoutParams(RecyclerView.LayoutParams lp); void setSpanSizeLookup(SpanSizeLookup spanSizeLookup); SpanSizeLookup getSpanSizeLookup(); @Override void setMeasuredDimension(Rect childrenBounds, int wSpec, int hSpec); @Override int scrollHorizontallyBy(int dx, RecyclerView.Recycler recycler,
            RecyclerView.State state); @Override int scrollVerticallyBy(int dy, RecyclerView.Recycler recycler,
            RecyclerView.State state); int getSpanCount(); void setSpanCount(int spanCount); @Override View onFocusSearchFailed(View focused, int focusDirection,
            RecyclerView.Recycler recycler, RecyclerView.State state); @Override boolean supportsPredictiveItemAnimations(); static final int DEFAULT_SPAN_COUNT; }### Answer:
@Test public void movingAGroupOffScreenForAddedItems() throws Throwable { final RecyclerView rv = setupBasic(new Config(3, 100)); final int[] maxId = new int[1]; maxId[0] = -1; final SparseIntArray spanLookups = new SparseIntArray(); final AtomicBoolean enableSpanLookupLogging = new AtomicBoolean(false); mGlm.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { @Override public int getSpanSize(int position) { if (maxId[0] > 0 && mAdapter.getItemAt(position).mId > maxId[0]) { return 1; } else if (enableSpanLookupLogging.get() && !rv.mState.isPreLayout()) { spanLookups.put(position, spanLookups.get(position, 0) + 1); } return 3; } }); ((SimpleItemAnimator) rv.getItemAnimator()).setSupportsChangeAnimations(true); waitForFirstLayout(rv); View lastView = rv.getChildAt(rv.getChildCount() - 1); final int lastPos = rv.getChildAdapterPosition(lastView); maxId[0] = mAdapter.getItemAt(mAdapter.getItemCount() - 1).mId; enableSpanLookupLogging.set(true); mGlm.expectLayout(2); mAdapter.addAndNotify(lastPos - 2, 30); mGlm.waitForLayout(2); checkForMainThreadException(); assertEquals("last items span count should be queried twice", 2, spanLookups.get(lastPos + 30)); }