GridLayoutManager will use a grid, and you can set some span, but not different heights for different cells.
What you want is a
StaggeredGridLayoutManager. This will just put the items on the screen if they fit, leading to your needed result. You can also change the reordering behavior, if you want to, by using