Create your account

Already have an account? Login here

Note: By joining, you will receive periodic emails from Coursetro. You can unsubscribe from these emails.

Create account

73. Add Divider To The RecyclerView

Design + Code an Android App from Scratch

Woah, wait a second..

Scrounge up some loose change to become a pro member, or login to your account to view this lesson.

Alright, join now. Or login to your account if you're already a pro member.

This video shows you how to add a divider to our RecyclerView. In the first step, we make a drawable that contains a shape representing our divider with a solid colour. In the second step, we create a class called Divider that inherits from RecyclerView.ItemDecoration. We then override the onDraw method that lets us draw a horizontal divider after detecting the orientation of the LinearLayoutManager. We override the getItemOffsets method to specify spacing between the items where the divider will be drawn. We then calculate the left, top, right and bottom values for the divider and draw it for each child in the RecyclerView.

Course Cirriculum