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
You can change the layout manager to GridLayoutManager and define the "span size" for the header, for example, if you want the grid with 2 columns, the header should have span size 2 and the children span size 1:
GridLayoutManager glm = new GridLayoutManager(getContext(), 2);
glm.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
switch(getTypeForPosition(position)) {
case HEADER:
return 2;
default:
return 1;
}
}
});
recyclerView.setLayoutManager(glm);
There is a full example of expandable grid with headers here using this library.