Margin between items in recycler view Android
I faced similar issue, with RelativeLayout as the root element for each row in the recyclerview.
To solve the issue, find the xml file that holds each row and make sure that the root element's height is wrap_content
NOT match_parent
.
Improve spacing between recycleView items
What you're asking for is something with the visual look of a Chip from Material Components. While the documentation for Chips suggests putting them in a ChipGroup, this loses the benefit of recycling views if you have more than enough to cover the screen. On the other hand, if they need to behave like a RadioGroup, where you can select only one to be toggled at a time, then ChipGroup would be easier to use.
To do this with RecylerView, you can change your item view layouts to use a Chip instead of a TextView. Set the item's layout width to wrapContent
. Then use Google's Flexbox Layout library to get the layout with variable length items.
In Gradle dependencies: implementation 'com.google.android.flexbox:flexbox:3.0.0'
In your activity:
recyclerView.layoutManager = FlexboxLayoutManager(this)
.apply { flexDirection = FlexDirection.ROW }
Result:
There's a related question here that is helpful.
Related Topics
How to Change Theme For Alertdialog
How to Check the Current Status of the Gps Receiver
Height of Status Bar in Android
Android Sqlite Database: Slow Insertion
How to Restart Activity in Android
Set Style For Textview Programmatically
How to Change an Android App'S Name
Getapplication() Vs. Getapplicationcontext()
Android - How to Override the "Back" Button So It Doesn't Finish() My Activity
How to Add a Footer in Listview
Getting the Screen Density Programmatically in Android
How to Detect If Software Keyboard Is Visible on Android Device or Not
Passing Android Bitmap Data Within Activity Using Intent in Android
Difference Between Compilesdkversion and Targetsdkversion
How to Create a Custom-Shaped Bitmap Marker With Android Map API V2