我想要实现带有区域标题的网格布局。可以参考https://github.com/TonicArtos/StickyGridHeaders
目前我的做法是:
mRecyclerView = (RecyclerView) view.findViewById(R.id.grid);
mLayoutManager = new GridLayoutManager(getActivity(), 2);
mLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
switch(mAdapter.getItemViewType(position)){
case MyAdapter.TYPE_HEADER:
return 1;
case MyAdapter.TYPE_ITEM:
return 2;
default:
return -1;
}
}
});
mRecyclerView.setLayoutManager(mLayoutManager);
现在普通项目和标题都具有1的span大小。我该怎么解决?
mAdapter.getItemViewType(position)
是否返回了正确的值吗? - yigit