Skip to content

Most visited

Recently visited

navigation

GridLayoutManager.SpanSizeLookup

public static abstract class GridLayoutManager.SpanSizeLookup
extends Object

java.lang.Object
   ↳ android.support.v7.widget.GridLayoutManager.SpanSizeLookup
Known Direct Subclasses


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

Default implementation sets each item to occupy exactly 1 span.

See also:

Summary

Public constructors

GridLayoutManager.SpanSizeLookup()

Public methods

int getSpanGroupIndex(int adapterPosition, int spanCount)

Returns the index of the group this position belongs.

int getSpanIndex(int position, int spanCount)

Returns the final span index of the provided position.

abstract int getSpanSize(int position)

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

void invalidateSpanIndexCache()

Clears the span index cache.

boolean isSpanIndexCacheEnabled()

Returns whether results of getSpanIndex(int, int) method are cached or not.

void setSpanIndexCacheEnabled(boolean cacheSpanIndices)

Sets whether the results of getSpanIndex(int, int) method should be cached or not.

Inherited methods

From class java.lang.Object

Public constructors

GridLayoutManager.SpanSizeLookup

added in version 22.0.0
GridLayoutManager.SpanSizeLookup ()

Public methods

getSpanGroupIndex

added in version 22.0.0
int getSpanGroupIndex (int adapterPosition, 
                int spanCount)

Returns the index of the group this position belongs.

For example, if grid has 3 columns and each item occupies 1 span, span group index for item 1 will be 0, item 5 will be 1.

Parameters
adapterPosition int: The position in adapter
spanCount int: The total number of spans in the grid
Returns
int The index of the span group including the item at the given adapter position

getSpanIndex

added in version 22.0.0
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 (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 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 int: The position of the item
spanCount int: The total number of spans in the grid
Returns
int The final span position of the item. Should be between 0 (inclusive) and spanCount(exclusive)

getSpanSize

added in version 22.0.0
int getSpanSize (int position)

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

Parameters
position int: The adapter position of the item
Returns
int The number of spans occupied by the item at the provided position

invalidateSpanIndexCache

added in version 22.0.0
void invalidateSpanIndexCache ()

Clears the span index cache. GridLayoutManager automatically calls this method when adapter changes occur.

isSpanIndexCacheEnabled

added in version 22.0.0
boolean isSpanIndexCacheEnabled ()

Returns whether results of getSpanIndex(int, int) method are cached or not.

Returns
boolean True if results of getSpanIndex(int, int) are cached.

setSpanIndexCacheEnabled

added in version 22.0.0
void setSpanIndexCacheEnabled (boolean cacheSpanIndices)

Sets whether the results of getSpanIndex(int, int) method should be cached or not. By default these values are not cached. If you are not overriding getSpanIndex(int, int), you should set this to true for better performance.

Parameters
cacheSpanIndices boolean: Whether results of getSpanIndex should be cached or not.
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a one-minute survey?
Help us improve Android tools and documentation.