我在布局中使用5个跨度计数的RecyclerViewGridLayoutManager

如何通过项目位置确定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();
}

10-08 03:14