-
public abstract class GridLayoutManager.SpanSizeLookup
A helper class to provide the number of spans each item occupies.
Default implementation sets each item to occupy exactly 1 span.
-
-
Method Summary
Modifier and Type Method Description abstract int
getSpanSize(int position)
Returns the number of span occupied by the item at position
.void
setSpanIndexCacheEnabled(boolean cacheSpanIndices)
Sets whether the results of getSpanIndex method should be cached ornot. void
setSpanGroupIndexCacheEnabled(boolean cacheSpanGroupIndices)
Sets whether the results of getSpanGroupIndex method should be cachedor not. void
invalidateSpanIndexCache()
Clears the span index cache. void
invalidateSpanGroupIndexCache()
Clears the span group index cache. boolean
isSpanIndexCacheEnabled()
Returns whether results of getSpanIndex method are cached or not. boolean
isSpanGroupIndexCacheEnabled()
Returns whether results of getSpanGroupIndex method are cached or not. int
getSpanIndex(int position, int spanCount)
Returns the final span index of the provided position. int
getSpanGroupIndex(int adapterPosition, int spanCount)
Returns the index of the group this position belongs. -
-
Method Detail
-
getSpanSize
abstract int getSpanSize(int position)
Returns the number of span occupied by the item at
position
.- Parameters:
position
- The adapter position of the item
-
setSpanIndexCacheEnabled
void setSpanIndexCacheEnabled(boolean cacheSpanIndices)
Sets whether the results of getSpanIndex method should be cached ornot. By default these values are not cached. If you are not overriding getSpanIndex with something highly performant, you should set thisto true for better performance.
- Parameters:
cacheSpanIndices
- Whether results of getSpanIndex should be cached or not.
-
setSpanGroupIndexCacheEnabled
void setSpanGroupIndexCacheEnabled(boolean cacheSpanGroupIndices)
Sets whether the results of getSpanGroupIndex method should be cachedor not. By default these values are not cached. If you are not overriding getSpanGroupIndex with something highly performant, and you are usingspans to calculate scrollbar offset and range, you should set this to true for betterperformance.
- Parameters:
cacheSpanGroupIndices
- Whether results of getGroupSpanIndex should be cached ornot.
-
invalidateSpanIndexCache
void invalidateSpanIndexCache()
Clears the span index cache. GridLayoutManager automatically calls this method whenadapter changes occur.
-
invalidateSpanGroupIndexCache
void invalidateSpanGroupIndexCache()
Clears the span group index cache. GridLayoutManager automatically calls this methodwhen adapter changes occur.
-
isSpanIndexCacheEnabled
boolean isSpanIndexCacheEnabled()
Returns whether results of getSpanIndex method are cached or not.
-
isSpanGroupIndexCacheEnabled
boolean isSpanGroupIndexCacheEnabled()
Returns whether results of getSpanGroupIndex method are cached or not.
-
getSpanIndex
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 overridethis method. Otherwise, you should enable span index cache(setSpanIndexCacheEnabled) for better performance. When caching isdisabled, default implementation traverses all items from 0 to
position
. When caching is enabled, it calculates from the closest cachedvalue before theposition
.If you override this method, you need to make sure it is consistent with getSpanSize. GridLayoutManager does not call this method foreach item. It is called only for the reference item and rest of the itemsare assigned to spans based on the reference item. For example, you cannot assign aposition 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 itemspanCount
- The total number of spans in the grid
-
getSpanGroupIndex
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 indexfor item 1 will be 0, item 5 will be 1.
- Parameters:
adapterPosition
- The position in adapterspanCount
- The total number of spans in the grid
-
-
-
-