I want to have a RecyclerView which is foldable like expandable ListView and the children of each paren will present a GridView layout manager.
Is it possible? Can anyone direct me on how to do that? Thanks
I want to have a RecyclerView which is foldable like expandable ListView and the children of each paren will present a GridView layout manager.
Is it possible? Can anyone direct me on how to do that? Thanks
There is a full example here of how implement an Expandable GridView using this library.
Basically you use the library to group your items into sections in order to have a header for each section but you can implement it yourself.
Then you add a GridLayoutManager
, define how many columns per row (2 in this example) and set the header to have a span size of 2 columns per row and children to have a span size of 1 column per row:
GridLayoutManager glm = new GridLayoutManager(getContext(), 2);
glm.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
switch(sectionAdapter.getSectionItemViewType(position)) {
case SectionedRecyclerViewAdapter.VIEW_TYPE_HEADER:
return 2;
default:
return 1;
}
}
});
recyclerView.setLayoutManager(glm);
In order to expand/collapse the sections, check the use of the expanded
variable in the example.
You can use this example of Expandable RecyclerView . It provides an Expandable RecyclerView with group items that can be individually expanded to show its children in a two-dimensional scrolling grid. Each grid item can be selected.
This how it works : Each ChildViewHolder object receives a data array from RecyclerView adapter to display in a grid row. Then it breaks up the layout of its row in rectangular cells of equal size. Each cell displays a piece of data.
Hope this will help anyone looking for this.
You can use Expandable RecyclerVew
and for children view use other RecyclerView
with GridLayoutManager