Skip to content Skip to sidebar Skip to footer

How To Use A Viewpager2 Inside Another Viewpager2

I use a ViewPager2 inside another ViewPager2. Because of this, the slide only works for the root ViewPager. How to make both ViewPager work?

Solution 1:

As the documentation says :

"Support nested scrollable elements

ViewPager2 does not natively support nested scroll views in cases where the scroll view has the same orientation as the ViewPager2 object that contains it. For example, scrolling would not work for a vertical scroll view inside a vertically-oriented ViewPager2 object.

To support a scroll view inside a ViewPager2 object with the same orientation, you must call requestDisallowInterceptTouchEvent() on the ViewPager2 object when you expect to scroll the nested element instead. The ViewPager2 nested scrolling sample demonstrates one way of solving this problem with a versatile custom wrapper layout."

I have tried it myself and it works just fine, you need to use this class.

And this is the link to the documentation.

Solution 2:

mPager.setNestedScrollingEnabled(true) for child views

Post a Comment for "How To Use A Viewpager2 Inside Another Viewpager2"