Adapters are only responsible for creating and managing views for items (called ViewHolder), these classes do not decide how these views are arranged when displaying them. Instead, they rely on a separate class called LayoutManager.
LayoutManager is a class that tells Adapters how to arrange those items. For example, you might want those items in a single row top to bottom or you may want them arranged in Grids like Gallery. Instead of writing this logic in your adapter, you write it in LayoutManager and pass that LayoutManager to View (RecyclerView).
A beginner might ask, Why does it work like that?
Answer: Flexibility. By using this pattern, whenever you want to change the arrangement of items, you don't have to modify Adapters or RecyclerView. Moreover, without this approach, you would be limited to the functionality provided by the pre-built class. You can build your own LayoutManager by extending the LayoutManager class.
There are also some commonly used LayoutManagers included for you to use, I'll list two of them
- LinearLayoutManager
Arranges items in 1 column or 1 row based on orientation. For example, a horizontal
LinearLayoutManager will place items from left to right in 1 row.
- GridLayoutManager
Arranges items in a provided number of rows and columns, much like images in the gallery.