0
我在佈局中使用RecyclerView
和GridLayoutManager
,並有5個跨度數。如何確定網格佈局管理器的跨度索引?
如何通過項目位置確定GridLayoutManager
中項目的跨度索引?
我在佈局中使用RecyclerView
和GridLayoutManager
,並有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();
}