如何确定网格布局管理器的跨度索引?

How to determine span index of grid layout manager?

我在布局中使用 RecyclerViewGridLayoutManager,跨度数为 5。

如何根据项目位置确定GridLayoutManager中项目的跨度索引?

终于找到了! 根视图持有者项目的布局参数是 GridLayoutManager.LayoutParams 并且有 getSpanIndex() 方法。

RecyclerView.ViewHolder viewHolder = m_RecyclerView.findViewHolderForAdapterPosition(position);
if (viewHolder != null) {
    GridLayoutManager.LayoutParams lp = (GridLayoutManager.LayoutParams) viewHolder.itemView.getLayoutParams();
    int spanIndex = lp.getSpanIndex();
}