public static final class GridLayoutManager.DefaultSpanSizeLookup
extends GridLayoutManager.SpanSizeLookup
| java.lang.Object | ||
| android.support.v7.widget.GridLayoutManager.SpanSizeLookup | ||
| android.support.v7.widget.GridLayoutManager.DefaultSpanSizeLookup | ||
GridLayoutManager.SpanSizeLookup默认实现。 每个项目占用1个跨度。
Public constructors |
|
|---|---|
GridLayoutManager.DefaultSpanSizeLookup() |
|
公共方法(Public methods) |
|
|---|---|
int |
getSpanIndex(int position, int spanCount) 返回提供的位置的最终跨度索引。 |
int |
getSpanSize(int position) 返回 |
继承方法(Inherited methods) |
|
|---|---|
android.support.v7.widget.GridLayoutManager.SpanSizeLookup
|
|
java.lang.Object
|
|
GridLayoutManager.DefaultSpanSizeLookup ()
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 |