Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save FilipeLipan/ddbf97500cc2e6a5ac062ef15fe214bc to your computer and use it in GitHub Desktop.
Save FilipeLipan/ddbf97500cc2e6a5ac062ef15fe214bc to your computer and use it in GitHub Desktop.
Make grid RecyclerView change it span for some views
mRecyclerView = (RecyclerView) findViewById(R.id.rv);
list = generateData();
adapter = new ExpandableItemAdapter(list);
final GridLayoutManager manager = new GridLayoutManager(this, 3);
manager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
return adapter.getItemViewType(position) == ExpandableItemAdapter.TYPE_PERSON ? 1 : manager.getSpanCount();
}
});
mRecyclerView.setAdapter(adapter);
// important! setLayoutManager should be called after setAdapter
mRecyclerView.setLayoutManager(manager);
adapter.expandAll();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment