Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does anyone know how to do flow layout using RecyclerView?

Does anyone know how to do flow layout using RecyclerView?

How to change span count dynamically?

Answer :

Like this

like image 428
Bincy Baby Avatar asked Dec 01 '15 04:12

Bincy Baby


Video Answer


2 Answers

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.

like image 162
Rizwan Avatar answered Sep 20 '22 04:09

Rizwan


Here is the full example of using custom Library which acts like List GitHubLibrary TagLayout

  • Sample Code:-

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:-

enter image description here

like image 36
Hardy Avatar answered Sep 19 '22 04:09

Hardy