@Test public void spanGroupIndex() { final GridLayoutManager.SpanSizeLookup ssl = new GridLayoutManager.SpanSizeLookup() { @Override public int getSpanSize(int position) { if (position > 200) { return 100; } if (position > 6) { return 2; } return 1; } }; assertEquals(0, ssl.getSpanGroupIndex(0, 5)); assertEquals(0, ssl.getSpanGroupIndex(4, 5)); assertEquals(1, ssl.getSpanGroupIndex(5, 5)); assertEquals(1, ssl.getSpanGroupIndex(6, 5)); assertEquals(1, ssl.getSpanGroupIndex(7, 5)); assertEquals(2, ssl.getSpanGroupIndex(9, 5)); assertEquals(2, ssl.getSpanGroupIndex(8, 5)); }
private int getSpanGroupIndex(RecyclerView.Recycler recycler, RecyclerView.State state, int viewPosition) { if (!state.isPreLayout()) { return mSpanSizeLookup.getSpanGroupIndex(viewPosition, mSpanCount); } final int adapterPosition = recycler.convertPreLayoutPositionToPostLayout(viewPosition); if (adapterPosition == -1) { if (DEBUG) { throw new RuntimeException("Cannot find span group index for position " + viewPosition); } Log.w(TAG, "Cannot find span size for pre layout position. " + viewPosition); return 0; } return mSpanSizeLookup.getSpanGroupIndex(adapterPosition, mSpanCount); }
GridLayoutManager extends LinearLayoutManager { private int getSpanGroupIndex(RecyclerView.Recycler recycler, RecyclerView.State state, int viewPosition) { if (!state.isPreLayout()) { return mSpanSizeLookup.getSpanGroupIndex(viewPosition, mSpanCount); } final int adapterPosition = recycler.convertPreLayoutPositionToPostLayout(viewPosition); if (adapterPosition == -1) { if (DEBUG) { throw new RuntimeException("Cannot find span group index for position " + viewPosition); } Log.w(TAG, "Cannot find span size for pre layout position. " + viewPosition); return 0; } return mSpanSizeLookup.getSpanGroupIndex(adapterPosition, mSpanCount); } }
GridLayoutManager extends LinearLayoutManager { private int getSpanGroupIndex(RecyclerView.Recycler recycler, RecyclerView.State state, int viewPosition) { if (!state.isPreLayout()) { return mSpanSizeLookup.getSpanGroupIndex(viewPosition, mSpanCount); } final int adapterPosition = recycler.convertPreLayoutPositionToPostLayout(viewPosition); if (adapterPosition == -1) { if (DEBUG) { throw new RuntimeException("Cannot find span group index for position " + viewPosition); } Log.w(TAG, "Cannot find span size for pre layout position. " + viewPosition); return 0; } return mSpanSizeLookup.getSpanGroupIndex(adapterPosition, mSpanCount); } 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); }
GridLayoutManager extends LinearLayoutManager { private int getSpanGroupIndex(RecyclerView.Recycler recycler, RecyclerView.State state, int viewPosition) { if (!state.isPreLayout()) { return mSpanSizeLookup.getSpanGroupIndex(viewPosition, mSpanCount); } final int adapterPosition = recycler.convertPreLayoutPositionToPostLayout(viewPosition); if (adapterPosition == -1) { if (DEBUG) { throw new RuntimeException("Cannot find span group index for position " + viewPosition); } Log.w(TAG, "Cannot find span size for pre layout position. " + viewPosition); return 0; } return mSpanSizeLookup.getSpanGroupIndex(adapterPosition, mSpanCount); } 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(); }
GridLayoutManager extends LinearLayoutManager { private int getSpanGroupIndex(RecyclerView.Recycler recycler, RecyclerView.State state, int viewPosition) { if (!state.isPreLayout()) { return mSpanSizeLookup.getSpanGroupIndex(viewPosition, mSpanCount); } final int adapterPosition = recycler.convertPreLayoutPositionToPostLayout(viewPosition); if (adapterPosition == -1) { if (DEBUG) { throw new RuntimeException("Cannot find span group index for position " + viewPosition); } Log.w(TAG, "Cannot find span size for pre layout position. " + viewPosition); return 0; } return mSpanSizeLookup.getSpanGroupIndex(adapterPosition, mSpanCount); } 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; }