'How to make horizontal RecyclerView's left end right borders appear and disappear on scroll in Android

I want to show left and right borders as user scrolls horizontally. If there are enough items at the start only left border is shown, as the user scrolls both left end right border disappears and when the user reaches end of the scroll I want to show right border. If there are not enough items I want to show both borders. This is illustrated at the image bellow: enter image description here

What I currently have is this:

enter image description here

where I just put border drawable as RecyclerView background. This means that all the borders are always visible.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source