public final class

GridLayoutManager.DefaultSpanSizeLookup

extends GridLayoutManager.SpanSizeLookup

 java.lang.Object

androidx.recyclerview.widget.GridLayoutManager.SpanSizeLookup

↳androidx.recyclerview.widget.GridLayoutManager.DefaultSpanSizeLookup

Overview

Default implementation for GridLayoutManager.SpanSizeLookup. Each item occupies 1 span.

Summary

Constructors
publicDefaultSpanSizeLookup()

Methods
public intgetSpanIndex(int position, int spanCount)

Returns the final span index of the provided position.

public abstract intgetSpanSize(int position)

Returns the number of span occupied by the item at position.

from GridLayoutManager.SpanSizeLookupgetSpanGroupIndex, invalidateSpanGroupIndexCache, invalidateSpanIndexCache, isSpanGroupIndexCacheEnabled, isSpanIndexCacheEnabled, setSpanGroupIndexCacheEnabled, setSpanIndexCacheEnabled
from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public DefaultSpanSizeLookup()

Methods

public abstract int getSpanSize(int position)

Returns the number of span occupied by the item at position.

Parameters:

position: The adapter position of the item

Returns:

The number of spans occupied by the item at the provided position

public int getSpanIndex(int position, int spanCount)

Returns the final span index of the provided position.

If you have a faster way to calculate span index for your items, you should override this method. Otherwise, you should enable span index cache (GridLayoutManager.SpanSizeLookup.setSpanIndexCacheEnabled(boolean)) for better performance. When caching is disabled, default implementation traverses all items from 0 to position. When caching is enabled, it calculates from the closest cached value before the position.

If you override this method, you need to make sure it is consistent with GridLayoutManager.SpanSizeLookup.getSpanSize(int). GridLayoutManager does not call this method for each item. It is called only for the reference item and rest of the items are assigned to spans based on the reference item. For example, you cannot assign a position to span 2 while span 1 is empty.

Note that span offsets always start with 0 and are not affected by RTL.

Parameters:

position: The position of the item
spanCount: The total number of spans in the grid

Returns:

The final span position of the item. Should be between 0 (inclusive) and spanCount(exclusive)