Multiple view types

RecyclerView is capable of handling almost any number of different types of widgets for display on the screen, and recycling them all independently. This is an amazingly powerful and useful technique, not just for being able to display different types of data on the screen, but also to adjust the layout of the RecyclerView in a way that is mostly transparent. However, you'll need to look at how exactly you want to break the layout up.

There are generally two main reasons you will want to use different view types in a RecyclerView:

  • To break up a long list of items with a divider
  • As you have different types of data you want to render together

Let's start with creating and adding dividers; you can just adjust the margin ...

Get Hands-On Android UI Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.