Add divider lines to RecyclerView items

suggest change

Just add these lines to the initialization

RecyclerView mRecyclerView = (RecyclerView) view.findViewById(recyclerView);
mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
mRecyclerView.addItemDecoration(new DividerItemDecoration(getActivity(), DividerItemDecoration.VERTICAL));

Add an adapter and call .notifyDataSetChanged(); as usual ! This is not an inbuilt feature of Recyclerview but added in the support libraries. So don’t forget to include this in your app level build.gradle file

compile ""
compile ""
Multiple ItemDecorations can be added to a single RecyclerView.

Changing divider color :

It’s pretty easy to set an color for a itemDecoration.

  1. step is: creating a divider.xml file which is located on drawable folder
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android=""
    <solid android:color="@color/divider_color"/>
  1. step is: setting drawable
// Get drawable object
Drawable mDivider = ContextCompat.getDrawable(m_jContext, R.drawable.divider);
// Create a DividerItemDecoration whose orientation is Horizontal
DividerItemDecoration hItemDecoration = new DividerItemDecoration(m_jContext,
// Set the drawable on it
// Create a DividerItemDecoration whose orientation is vertical
DividerItemDecoration vItemDecoration = new DividerItemDecoration(m_jContext,
// Set the drawable on it

Feedback about page:

Optional: your email if you want me to get back to you:

Table Of Contents