Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RecyclerView add divider lines only between some items

I want to add divider lines in my RecyclerView Layout. I already searched some time, but I can only find solutions that utilise RecyclerView.addItemDecoration, which adds the divider between all items. I could create a layout that has a single line and add that to the RecyclerView, but that doesn't seem like an elegant solution to me.

like image 386
BBotMerlin Avatar asked Jan 30 '23 19:01

BBotMerlin


1 Answers

DividerItemDecoration myDivider = new DividerItemDecoration(context, DividerItemDecoration.VERTICAL);

myDivider.setDrawable(ContextCompat.getDrawable(context, R.drawable.cutm_dvdr));
yourRecyclerView.addItemDecoration(myDivider);

add cutm_dvdr.xml in drawable folder

 <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
        <size android:height="1dp" />
        <solid android:color="#e20" />
    </shape>
like image 95
Mohd Saquib Avatar answered Feb 01 '23 10:02

Mohd Saquib