Layout Managers (Recycler View)

Metehan Bolat
2 min readJun 16, 2022

--

If you are working with lists, you have probably used adapters. On Android we mostly use RecyclerView. This story is not about RecyclerView. It is related to the Layout Manager we use in RecyclerView.

A LayoutManager is responsible for measuring and positioning item views within a RecyclerView as well as determining the policy for when to recycle item views that are no longer visible to the user. For more detailed information about Layout manager, you can click here.

There are 3 types of Layout Managers.

  • LinearLayoutManager
  • GridLayoutManager
  • StaggeredGridLayoutManager

Linear Layout Manager

Linear Layout Manager

Grid Layout Manager

Grid Layout Manager

Staggered Grid Layout Manager

Staggered Grid Layout Manager

I think it is more correct to express it with visuals in order to understand the Layout Managers. Layout Managers have many functions that we can change. In this story we will see the class LinearSmoothScroller using the smoothScroolToPosition function.

We create a class that inherits from the Linear Layout Manager. By overriding the smoothScroolToPosition function, we can show an animated transition to the index we want in the list. If we want, we can even adjust the animation speed by overriding the calculateSpeedPerPixel function within the LinearSmoothScroller structure.

Required Codes

The rest is exactly as you know. Create a normal recycler view adapter. Set the layout manager of the recyclerview you created in your design as the layout manager you created.

an Example for Recycler View Layout Manager

If you want, you can find the source code of the sample project here. If you want to learn how the sample project is coded, you can also watch this video.

Thanks for reading this story. I hope it was useful.

Photo by Pete Pedroza on Unsplash

--

--