Awesome RecyclerView

Alexey Kovalev
AndroidPub
Published in
2 min readAug 23, 2017

Most probably everyone from Android community had working experience with RecyclerView component. Though our every day’s tasks usually bound to its default usage — horizontal/vertical lists or grid of items and built in layout managers like LinearLayoutManager , GridLayoutManager , etc. That’s it — it’s usually enough for our needs.

But what if we want to move beyond its ordinal use case? What should we know about this component?

Fortunately RecyclerView was designed as flexible and modular replacement of legacy ListView . Its hidden power and flexibility is buried inside it integral parts like Adapter , LayoutManager ,SmoothScroller , ItemDecoration , etc.

I would like to take your time and pay your attention to how RecyclerView can be adopted for positioning views in nonlinear way — like a sectors of the rotating carousel which can be smoothly scrolled in up/down directions.

Without further into please take a look at this video to have a feeling what is about:

Such behavior can be achieved by creating custom LayoutManger

From the official documentation

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. By changing the LayoutManager a RecyclerView can be used to implement a standard vertically scrolling list, a uniform grid, staggered grids, horizontally scrolling collections and more. Several stock layout managers are provided for general use.

So it means that by creating our own implementation of LayoutManger we are able to position RecyclerView ‘s children in a necessary way.

During one of my projects, I was involved in the creation of unique EPG (Electronic Program Guide) component where channel assets would be sectors of the rotating carousel and channel’s content would be scrollable horizontal stripe of assets with ability to select and playback chosen TV/VOD item.

Unfortunately, that project did not go live due to budget limitations. But the component was created and eventually I decided to open source it.

So if you are interested in further details of component’s implementation please visit its GitHub page

--

--