StaggeredGridLayoutManager

public class StaggeredGridLayoutManager
extends RecyclerView.LayoutManager implements RecyclerView.SmoothScroller.ScrollVectorProvider

java.lang.Object
   ↳ androidx.recyclerview.widget.RecyclerView.LayoutManager
     ↳ androidx.recyclerview.widget.StaggeredGridLayoutManager


A LayoutManager that lays out children in a staggered grid formation. It supports horizontal & vertical layout as well as an ability to layout children in reverse.

Staggered grids are likely to have gaps at the edges of the layout. To avoid these gaps, StaggeredGridLayoutManager can offset spans independently or move items between spans. You can control this behavior via setGapStrategy(int).

Summary

Nested classes

class StaggeredGridLayoutManager.LayoutParams

LayoutParams used by StaggeredGridLayoutManager. 

Constants

int GAP_HANDLING_LAZY

This constant is deprecated. No longer supported.

int GAP_HANDLING_MOVE_ITEMS_BETWEEN_SPANS

When scroll state is changed to RecyclerView.SCROLL_STATE_IDLE, StaggeredGrid will check if there are gaps in the because of full span items.

int GAP_HANDLING_NONE

Does not do anything to hide gaps.

int HORIZONTAL

int VERTICAL

Public constructors

StaggeredGridLayoutManager(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)

Constructor used when layout manager is set in XML by RecyclerView attribute "layoutManager".

StaggeredGridLayoutManager(int spanCount, int orientation)

Creates a StaggeredGridLayoutManager with given parameters.

Public methods

void assertNotInLayoutOrScroll(String message)

Checks if RecyclerView is in the middle of a layout or scroll and throws an IllegalStateException if it is.

boolean canScrollHorizontally()

Query if horizontal scrolling is currently supported.

boolean canScrollVertically()

Query if vertical scrolling is currently supported.

boolean checkLayoutParams(RecyclerView.LayoutParams lp)

Determines the validity of the supplied LayoutParams object.

int computeHorizontalScrollExtent(RecyclerView.State state)

Override this method if you want to support scroll bars.

int computeHorizontalScrollOffset(RecyclerView.State state)

Override this method if you want to support scroll bars.

int computeHorizontalScrollRange(RecyclerView.State state)

Override this method if you want to support scroll bars.

PointF computeScrollVectorForPosition(int targetPosition)

Should calculate the vector that points to the direction where the target position can be found.

int computeVerticalScrollExtent(RecyclerView.State state)

Override this method if you want to support scroll bars.

int computeVerticalScrollOffset(RecyclerView.State state)

Override this method if you want to support scroll bars.

int computeVerticalScrollRange(RecyclerView.State state)

Override this method if you want to support scroll bars.

int[] findFirstCompletelyVisibleItemPositions(int[] into)

Returns the adapter position of the first completely visible view for each span.

int[] findFirstVisibleItemPositions(int[] into)

Returns the adapter position of the first visible view for each span.

int[] findLastCompletelyVisibleItemPositions(int[] into)

Returns the adapter position of the last completely visible view for each span.

int[] findLastVisibleItemPositions(int[] into)

Returns the adapter position of the last visible view for each span.

RecyclerView.LayoutParams generateDefaultLayoutParams()

Create a default LayoutParams object for a child of the RecyclerView.

RecyclerView.LayoutParams generateLayoutParams(Context c, AttributeSet attrs)

Create a LayoutParams object suitable for this LayoutManager from an inflated layout resource.

RecyclerView.LayoutParams generateLayoutParams(ViewGroup.LayoutParams lp)

Create a LayoutParams object suitable for this LayoutManager, copying relevant values from the supplied LayoutParams object if possible.

int getGapStrategy()

Returns the current gap handling strategy for StaggeredGridLayoutManager.

int getOrientation()
boolean getReverseLayout()

Returns whether views are laid out in reverse order or not.

int getSpanCount()