Reputation: 732
In my app i am using a recycler view that contains a number of items, i want to show a doted separator(divider) line between the items but its not working. I have tried creating a drawable shape but afer adding drawable to DividerItemDecoration no space or line showing between the recycler view items. I have tried creating custom DividerItemDecoration class too but nothing works for me. NOTE: Currently in my drawable shape is set to rectangle i have tried line too. How it can be achieved. Any help will be appreciated. Here is my code.
Drawable:(customdrawableshape.xml)
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke
android:width="3dp"
android:height="2dp"
android:color="#000000"
android:dashGap="10dp"
android:dashWidth="5dp" />
</shape>
Custom row for recycler view items
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginBottom="2dp">
<TextView
android:id="@+id/tv_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
And the part of code where i am setting item decoration to recyclerview
DividerItemDecoration dividerItemDecoration;
recyclerview.setLayoutManager(linearlayoutmanager);
dividerItemDecoration = new DividerItemDecoration(recyclerview.getContext(),
linearlayoutmanager.getOrientation());
dividerItemDecoration.setDrawable(ContextCompat.getDrawable(context, R.drawable.customdrawableshape));
recyclerview.addItemDecoration(dividerItemDecoration);
Upvotes: 2
Views: 10535
Reputation: 253
Kotlin Version:
recyclerview.addItemDecoration(DividerItemDecoration(this, DividerItemDecoration.VERTICAL))
Upvotes: 0
Reputation: 2342
you can use DividerItemDecoration
class for adding lines.
here is example code
recyclerView.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL));
Upvotes: 15