Created
July 20, 2017 13:20
-
-
Save FilipeLipan/ddbf97500cc2e6a5ac062ef15fe214bc to your computer and use it in GitHub Desktop.
Make grid RecyclerView change it span for some views
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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