How to make first item of RecyclerView of Full Width with a GridLayoutManager

Anil S
Dev Journal
Published in
1 min readApr 14, 2018

Look at the above image. Both have same layoutmanager (GridLayoutManager). The left side looks better as the first item is bookmarks and It should be of full-width (match_parent).

There’s a little workaround for this. You just have to add spanSizeLookup command which will look at the desired position (in our case, it’s 0, first pos) and set the span size of layout manager items in RecyclerView.

All you need to take care is that the layout manager for your recyclerView should be GridLayoutManager. The rest of your code remains same.

In this case, the number of spans is set as 2 (NUM_GRIDS). RecyclerView now shows the list items in two grids. When adding the above code, we set the first item to take width of two spans.

You can even set different span sizes for different positions as per you app needs. Clap it this helps.

--

--