Android: Add divider between items in RecyclerView

android, android-recyclerview, android-styles, xml

Solution

you should try add Divider

mListview.addItemDecoration(new DividerItemDecoration(this.getActivity(), LinearLayout.VERTICAL));

Problem

I am using `RecyclerView` with rounded corner, to make it rounded corner I used below XML: view_rounded.xml:- ``` <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <solid android:color="#008f8471"/> <stroke android:width="2dp" android:color="#ffffff" /> <corners android:radius="10dp"/> </shape> ``` fragment_main.xml:- ``` <android.support.v7.widget.RecyclerView android:id="@+id/recycler_view" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/view_rounded"/> ``` adapter_main.xml:- ``` <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/LinearLayout1" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <TextView android:id="@+id/textTitle" style="@style/AppTheme.ListTextView" /> </LinearLayout> ``` style.xml:- ``` <style name="AppTheme.ListTextView" parent="android:Widget.Material.TextView"> <item name="android:gravity">left</item> <item name="android:layout_width">match_parent</item> <item name="android:layout_height">wrap_content</item> <item name="android:textAllCaps">false</item> <item name="android:padding">10dp</item> <item name="android:textAppearance">@android:style/TextAppearance.DeviceDefault.Medium</item> <item name="android:textColor">@color/tabsScrollColor</item> <item name="android:textStyle">bold</item> </style> ``` Getting (without item separator): Required (with item separator):

Original source

Related problems