Changing layout managers for different views in RecyclerView

后端 未结 2 769
独厮守ぢ
独厮守ぢ 2021-02-06 04:08

I implemented an expandable recyclerview with child elements that are part of the list. I followed this code. This is how it works,

The implementation of

2条回答
  •  北荒
    北荒 (楼主)
    2021-02-06 04:34

    change the layout manager to gridlayout manager and handle the span size as mentioned below

    layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
                @Override
                public int getSpanSize(int position) {
                    int type=mAdapter.getItemViewType(position);
                    if (type == "view holder type name")
                        return 2;
                    else
                        return 1;
                }
            });
    

提交回复
热议问题