added in version 22.1.0
belongs to Maven artifact com.android.support:recyclerview-v7:28.0.0-alpha1

GridLayoutManager

public class GridLayoutManager
extends LinearLayoutManager

java.lang.Object
   ↳ android.support.v7.widget.RecyclerView.LayoutManager
     ↳ android.support.v7.widget.LinearLayoutManager
       ↳ android.support.v7.widget.GridLayoutManager


A RecyclerView.LayoutManager implementations that lays out items in a grid.

By default, each item occupies 1 span. You can change it by providing a custom GridLayoutManager.SpanSizeLookup instance via setSpanSizeLookup(SpanSizeLookup).

Summary

Nested classes

class GridLayoutManager.DefaultSpanSizeLookup

Default implementation for GridLayoutManager.SpanSizeLookup

class GridLayoutManager.LayoutParams

LayoutParams used by GridLayoutManager. 

class GridLayoutManager.SpanSizeLookup

A helper class to provide the number of spans each item occupies. 

XML attributes

RecyclerView_spanCount  

Inherited XML attributes

From class android.support.v7.widget.LinearLayoutManager
From class android.support.v7.widget.RecyclerView.LayoutManager

Constants

int DEFAULT_SPAN_COUNT

Inherited constants

From class android.support.v7.widget.LinearLayoutManager

Public constructors

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

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

GridLayoutManager(Context context, int spanCount)

Creates a vertical GridLayoutManager

GridLayoutManager(Context context, int spanCount, int orientation, boolean reverseLayout)

Public methods

boolean checkLayoutParams(RecyclerView.LayoutParams lp)

Determines the validity of the supplied LayoutParams object.

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 getColumnCountForAccessibility(RecyclerView.Recycler recycler, RecyclerView.State state)

Returns the number of columns for accessibility.

int getRowCountForAccessibility(RecyclerView.Recycler recycler, RecyclerView.State state)

Returns the number of rows for accessibility.

int getSpanCount()

Returns the number of spans laid out by this grid.

GridLayoutManager.SpanSizeLookup getSpanSizeLookup()

Returns the current GridLayoutManager.SpanSizeLookup used by the GridLayoutManager.

View onFocusSearchFailed(View focused, int focusDirection, RecyclerView.Recycler recycler, RecyclerView.State state)

Called when searching for a focusable view in the given direction has failed for the current content of the RecyclerView.

void onInitializeAccessibilityNodeInfoForItem(RecyclerView.Recycler recycler, RecyclerView.State state, View host, AccessibilityNodeInfoCompat info)

Called by the AccessibilityDelegate when the accessibility information for a specific item should be populated.

void onItemsAdded(RecyclerView recyclerView, int positionStart, int itemCount)

Called when items have been added to the adapter.

void onItemsChanged(RecyclerView recyclerView)

Called in response to a call to notifyDataSetChanged() or swapAdapter(Adapter, boolean) ()} and signals that the the entire data set has changed.

void onItemsMoved(RecyclerView recyclerView, int from, int to, int itemCount)

Called when an item is moved withing the adapter.

void onItemsRemoved(RecyclerView recyclerView, int positionStart, int itemCount)

Called when items have been removed from the adapter.

void onItemsUpdated(RecyclerView recyclerView, int positionStart, int itemCount, Object payload)

Called when items have been changed in the adapter and with optional payload.

void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state)

Lay out all relevant child views from the given adapter.

void onLayoutCompleted(RecyclerView.State state)

Called after a full layout calculation is finished.

int scrollHorizontallyBy(int dx, RecyclerView.Recycler recycler, RecyclerView.State state)

Scroll horizontally by dx pixels in screen coordinates and return the distance traveled.

int scrollVerticallyBy(int dy, RecyclerView.Recycler recycler, RecyclerView.State state)

Scroll vertically by dy pixels in screen coordinates and return the distance traveled.

void setMeasuredDimension(Rect childrenBounds, int wSpec, int hSpec)

Sets the measured dimensions from the given bounding box of the children and the measurement specs that were passed into onMeasure(int, int).

void setSpanCount(int spanCount)

Sets the number of spans to be laid out.

void setSpanSizeLookup(GridLayoutManager.SpanSizeLookup spanSizeLookup)

Sets the source to get the number of spans occupied by each item in the adapter.

void setStackFromEnd(boolean stackFromEnd)

stackFromEnd is not supported by GridLayoutManager.

boolean supportsPredictiveItemAnimations()

Returns whether this LayoutManager supports "predictive item animations".

Inherited methods

From class android.support.v7.widget.LinearLayoutManager