How can a divider line be added in an Android RecyclerView?

sofquestion 8 picture sofquestion 8 · Jul 6, 2015 · Viewed 200.6k times · Source

I am developing an android application where I am using RecyclerView. I need to add a divider in RecyclerView. I tried to add -

recyclerView.addItemDecoration(new
     DividerItemDecoration(getActivity(),
       DividerItemDecoration.VERTICAL_LIST));

below is my xml code -

   <android.support.v7.widget.RecyclerView
    android:id="@+id/drawerList"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="15dp"
    />

Answer

Aditya Vyas-Lakhan picture Aditya Vyas-Lakhan · Oct 24, 2016

In the October 2016 update, the support library v25.0.0 now has a default implementation of basic horizontal and vertical dividers available!

https://developer.android.com/reference/android/support/v7/widget/DividerItemDecoration.html

 recyclerView.addItemDecoration(new DividerItemDecoration(recyclerView.getContext(), DividerItemDecoration.VERTICAL));