Does anyone know how to do flow layout using RecyclerView?
How to change span count dynamically?
Answer :
Best solution is to use a RecyclerView with google FlexLayoutManager
// Set layout manager
val layoutManager = FlexboxLayoutManager(context)
recyclerview.layoutManager = layoutManager
// Now you can add your normal recyclerview adapter
recyclerview.adapter = MyListAdapter(list)
Add below dependency in your build.gradle file
implementation 'com.google.android:flexbox:2.0.1'
This will work like a charm.
Here is the full example of using custom Library which acts like List GitHubLibrary TagLayout
mFlowLayout.setAdapter(new TagAdapter<String>(mVals)
{
@Override
public View getView(FlowLayout parent, int position, String s)
{
TextView tv = (TextView) mInflater.inflate(R.layout.tv,
mFlowLayout, false);
tv.setText(s);
return tv;
}
});
Using below code you can pre set selection you wanted:-
mAdapter.setSelectedList(1,3,5,7,8,9);
Will show result like below:-
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With