GridLayoutManager

open class GridLayoutManager : LinearLayoutManager
kotlin.Any
   ↳ androidx.recyclerview.widget.RecyclerView.LayoutManager
   ↳ androidx.recyclerview.widget.LinearLayoutManager
   ↳ androidx.recyclerview.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 SpanSizeLookup instance via setSpanSizeLookup(SpanSizeLookup).

Summary

Nested classes
abstract

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

Default implementation for SpanSizeLookup.

open

LayoutParams used by GridLayoutManager.

Constants
static Int

Inherited constants
Public constructors
<init>(context: Context!, attrs: AttributeSet!, defStyleAttr: Int, defStyleRes: Int)

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

<init>(context: Context!, spanCount: Int)

Creates a vertical GridLayoutManager

<init>(context: Context!, spanCount: Int, orientation: Int, reverseLayout: Boolean)

Public methods
open Unit
onItemsAdded(recyclerView: RecyclerView, positionStart: Int, itemCount: Int)

open Int

open Int

open RecyclerView.LayoutParams!

open RecyclerView.LayoutParams!

open Unit

open Unit
setStackFromEnd(stackFromEnd: Boolean)

stackFromEnd is not supported by GridLayoutManager.

open View?
onFocusSearchFailed(focused: View, focusDirection: Int, recycler: RecyclerView.Recycler, state: RecyclerView.State)

open Boolean

open Unit
onItemsMoved(recyclerView: RecyclerView, from: Int, to: Int, itemCount: Int)

open Unit

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

open Int

open Unit

open Unit
onItemsUpdated(recyclerView: RecyclerView, positionStart: Int, itemCount: Int, payload: Any?)

open Unit
setMeasuredDimension(childrenBounds: Rect!, wSpec: Int, hSpec: Int)

open Int

open Unit
onItemsRemoved(recyclerView: RecyclerView, positionStart: Int, itemCount: Int)

open Boolean

open GridLayoutManager.SpanSizeLookup!

Returns the current SpanSizeLookup used by the GridLayoutManager.

open Unit

open Unit
setSpanCount(spanCount: Int)

Sets the number of spans to be laid out.

open Int

Returns the number of spans laid out by this grid.

open RecyclerView.LayoutParams!

open Unit

Inherited functions

Constants

DEFAULT_SPAN_COUNT

static val DEFAULT_SPAN_COUNT: Int
Value: -1

Public constructors

<init>

GridLayoutManager(context: Context!, attrs: AttributeSet!, defStyleAttr: Int, defStyleRes: Int)

Constructor used when layout manager is set in XML by RecyclerView attribute "layoutManager". If spanCount is not specified in the XML, it defaults to a single column. androidx.recyclerview.R.attr#spanCount

<init>

GridLayoutManager(context: Context!, spanCount: Int)

Creates a vertical GridLayoutManager

Parameters
context Context!: Current context, will be used to access resources.
spanCount Context!: The number of columns in the grid

<init>

GridLayoutManager(context: Context!, spanCount: Int, orientation: Int, reverseLayout: Boolean)
Parameters
context Context!: Current context, will be used to access resources.
spanCount Context!: The number of columns or rows in the grid
orientation Context!: Layout orientation. Should be HORIZONTAL or .
reverseLayout Context!: When set to true, layouts from end to start.

Public methods

onItemsAdded

open fun onItemsAdded(recyclerView: RecyclerView, positionStart: Int, itemCount: Int): Unit

scrollHorizontallyBy

open fun scrollHorizontallyBy(dx: Int, recycler: RecyclerView.Recycler!, state: RecyclerView.State!): Int

scrollVerticallyBy

open fun scrollVerticallyBy(dy: Int, recycler: RecyclerView.Recycler!, state: RecyclerView.State!): Int

generateLayoutParams

open fun generateLayoutParams(c: Context!, attrs: AttributeSet!): RecyclerView.LayoutParams!

generateLayoutParams

open fun generateLayoutParams(lp: LayoutParams!): RecyclerView.LayoutParams!

onInitializeAccessibilityNodeInfoForItem

open fun onInitializeAccessibilityNodeInfoForItem(recycler: RecyclerView.Recycler, state: RecyclerView.State, host: View, info: AccessibilityNodeInfoCompat): Unit

setStackFromEnd

open fun setStackFromEnd(stackFromEnd: Boolean): Unit

stackFromEnd is not supported by GridLayoutManager. Consider using setReverseLayout(boolean).

onFocusSearchFailed

open fun onFocusSearchFailed(focused: View, focusDirection: Int, recycler: RecyclerView.Recycler, state: RecyclerView.State): View?

supportsPredictiveItemAnimations

open fun supportsPredictiveItemAnimations(): Boolean

onItemsMoved

open fun onItemsMoved(recyclerView: RecyclerView, from: Int, to: Int, itemCount: Int): Unit

setSpanSizeLookup

open fun setSpanSizeLookup(spanSizeLookup: GridLayoutManager.SpanSizeLookup!): Unit

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

Parameters
spanSizeLookup GridLayoutManager.SpanSizeLookup!: SpanSizeLookup instance to be used to query number of spans occupied by each item

getColumnCountForAccessibility

open fun getColumnCountForAccessibility(recycler: RecyclerView.Recycler, state: RecyclerView.State): Int

onItemsChanged

open fun onItemsChanged(recyclerView: RecyclerView): Unit

onItemsUpdated

open fun onItemsUpdated(recyclerView: RecyclerView, positionStart: Int, itemCount: Int, payload: Any?): Unit

setMeasuredDimension

open fun setMeasuredDimension(childrenBounds: Rect!, wSpec: Int, hSpec: Int): Unit

getRowCountForAccessibility

open fun getRowCountForAccessibility(recycler: RecyclerView.Recycler, state: RecyclerView.State): Int

onItemsRemoved

open fun onItemsRemoved(recyclerView: RecyclerView, positionStart: Int, itemCount: Int): Unit

checkLayoutParams

open fun checkLayoutParams(lp: RecyclerView.LayoutParams!): Boolean

getSpanSizeLookup

open fun getSpanSizeLookup(): GridLayoutManager.SpanSizeLookup!

Returns the current SpanSizeLookup used by the GridLayoutManager.

Return
GridLayoutManager.SpanSizeLookup!: The current SpanSizeLookup used by the GridLayoutManager.

onLayoutCompleted

open fun onLayoutCompleted(state: RecyclerView.State!): Unit

setSpanCount

open fun setSpanCount(spanCount: Int): Unit

Sets the number of spans to be laid out.

If getOrientation() is VERTICAL, this is the number of columns. If getOrientation() is HORIZONTAL, this is the number of rows.

Parameters
spanCount Int: The total number of spans in the grid

See Also

getSpanCount

open fun getSpanCount(): Int

Returns the number of spans laid out by this grid.

Return
Int: The number of spans

generateDefaultLayoutParams

open fun generateDefaultLayoutParams(): RecyclerView.LayoutParams!

onLayoutChildren

open fun onLayoutChildren(recycler: RecyclerView.Recycler!, state: RecyclerView.State!): Unit