public static abstract class GridLayoutManager.SpanSizeLookup
extends Object
| java.lang.Object | |
| android.support.v7.widget.GridLayoutManager.SpanSizeLookup | |
| |
帮助类提供每个项目占用的跨度数量。
默认实现将每个项目设置为恰好占用1个范围。
Public constructors |
|
|---|---|
GridLayoutManager.SpanSizeLookup() |
|
公共方法(Public methods) |
|
|---|---|
int |
getSpanGroupIndex(int adapterPosition, int spanCount) 返回此位置所属组的索引。 |
int |
getSpanIndex(int position, int spanCount) 返回提供的位置的最终跨度索引。 |
abstract int |
getSpanSize(int position) 返回物品在 |
void |
invalidateSpanIndexCache() 清除跨度索引缓存。 |
boolean |
isSpanIndexCacheEnabled() 返回 |
void |
setSpanIndexCacheEnabled(boolean cacheSpanIndices) 设置是否应该缓存 |
继承方法(Inherited methods) |
|
|---|---|
java.lang.Object
|
|
GridLayoutManager.SpanSizeLookup ()
int getSpanGroupIndex (int adapterPosition,
int spanCount)
返回此位置所属组的索引。
例如,如果网格有3列,每个项目占用1个跨度,则项目1的跨度组索引将为0,项目5将为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 |
int getSpanIndex (int position,
int spanCount)
返回提供的位置的最终跨度索引。
如果您有更快的方法来计算项目的跨度索引,则应该重写此方法。 否则,应该启用跨度索引缓存( setSpanIndexCacheEnabled(boolean) )以获得更好的性能。 当禁用缓存时,默认实现将遍历从0到position所有项目。 当启用缓存时,它会根据position之前的最近缓存值进行position 。
如果您重写此方法,则需要确保它与getSpanSize(int)一致。 GridLayoutManager不会为每个项目调用此方法。 它仅被称为参考项目,其余项目被分配到基于参考项目的跨度。 例如,当span 1为空时,您无法将位置分配到span 2。
请注意,量程偏移总是从0开始,并且不受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) |
int getSpanSize (int position)
返回物品在 position处占用的跨度数。
| 参数(Parameters) | |
|---|---|
position |
int: The adapter position of the item |
| 返回(Returns) | |
|---|---|
int |
The number of spans occupied by the item at the provided position |
void invalidateSpanIndexCache ()
清除跨度索引缓存。 GridLayoutManager在发生适配器更改时自动调用此方法。
boolean isSpanIndexCacheEnabled ()
返回是否缓存 getSpanIndex(int, int)方法的结果。
| 返回(Returns) | |
|---|---|
boolean |
True if results of getSpanIndex(int, int) are cached. |
void setSpanIndexCacheEnabled (boolean cacheSpanIndices)
设置是否应缓存getSpanIndex(int, int)方法的结果。 默认情况下,这些值不会被缓存。 如果您不覆盖getSpanIndex(int, int) ,则应将其设置为true以获得更好的性能。
| 参数(Parameters) | |
|---|---|
cacheSpanIndices |
boolean: Whether results of getSpanIndex should be cached or not. |