How to reduce scroll sensitivity of ViewPager2 widget

Alexander Shevelev
1 min readJun 24, 2019

Sometimes you have complex nested layouts with ViewPager2. In my case, it was CoordinatorLayout with vertical scroll, ViewPager2 with a horizontal scroll inside the CoordinatorLayout and RecyclerView with a vertical scroll inside the ViewPager2 widget, oh my!

It’s a typical layout for the profile page of some social network. For example, open your Twitter app for Android and exam it’s user profile page. You can see a global scroll with your data (profile photo, etc.), tabs with your posts, and a list of posts inside every tab.

The main problem is scrolling. It’s tricky to scroll such screens smoothly, especially when hold your phone in one hand and try to scroll by a thumb.

The reason is simple — touch events interfere with each other. I came to the conclusion that reducing the scroll sensitivity of ViewPager2 is the simplest way to fix it. I studied the source code of the widget and made this simple extension:

It’s helped me to solve all the issues with ViewPager2 widget inside complex layouts. I hope it’ll help you too.

--

--

Alexander Shevelev

An Android developer from Yandex LLC, Moscow, Russia. That’s all.