I'm trying to use RecyclerView to display programmatically tags in my app. It would like this(sorry, i can't upload image to stackoverflow now)
http://anh.im/image/OUA
So, how can i create RecyclerView that show my contents left to right and auto new line at the right edge of RecyclerView look like the image and prevent it scroll horizontally? Thanks for any help!
Use implementation 'com.google.android:flexbox:1.0.0'
Just add in your recyclerview
val decoration = DividerItemDecoration(context, RecyclerView.HORIZONTAL)
decoration.setDrawable(ContextCompat.getDrawable(context, R.drawable.divider_10dp)!!)
recyclerViewSelectionList.addItemDecoration(decoration)
val layoutManager = FlexboxLayoutManager(this)
layoutManager.flexDirection = FlexDirection.ROW
layoutManager.justifyContent = JustifyContent.FLEX_START
recyclerViewSelectionList.layoutManager = layoutManager
Use implementation 'com.google.android.flexbox:flexbox:3.0.0'.
It's work for me!
FlexboxLayoutManager layoutManager = new FlexboxLayoutManager(getApplicationContext());
layoutManager.setFlexDirection(FlexDirection.ROW);
layoutManager.setJustifyContent(JustifyContent.FLEX_START);
recyclerView.setLayoutManager(layoutManager);
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