Sticky item in RecyclerView

Krzysztof Turek
5 min readAug 9, 2022

RecyclerView is a powerful component, widely used in Android projects. It is a successor to the old ListView. It allows not only to display data in an efficient way, but also to easily add customizable visual effects . I would like to describe one of these effects for you — a sticky item. Take a look at the image below.

The image presents a leaderboard of gold collected by users. John sees that his position is 11th. In comparison with others, his item has different colors. From John’s perspective, his position is the most important information on that screen, so it should be visible all the time. But what will happen when John wants to see the 1st or the 18th position? Will he lose the information about his position? We can solve that problem by sticking his item to the top or bottom of the screen like on the image below.

How do we do that? You can’t just tell RecyclerView not to scroll a certain item off-screen. It could mess up the whole recycling mechanism. In the programming world, if you can’t do something, you can still fake it…

--

--