8

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

Shamil
  • 83
  • 1
  • 3

3 Answers3

15

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.

Machavity
  • 30,841
  • 27
  • 92
  • 100
Tom3652
  • 2,540
  • 3
  • 19
  • 45
-1

mPager.setNestedScrollingEnabled(true) for child views

Crimiss
  • 1
  • 1
  • 1
    This solution does not work. This solutions works fine: https://github.com/android/views-widgets-samples/blob/master/ViewPager2/app/src/main/java/androidx/viewpager2/integration/testapp/NestedScrollableHost.kt – Piotr Badura Aug 10 '21 at 09:18
-1

I have tested the class, but the nestedScrollHost class does not use viewPager,this class uses a recycler instead of a viewpagers .

  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/33705621) – RusArtM Jan 30 '23 at 07:20
  • It is not an answer to the question it is a comment since stackover flow does not allow me to answer without reputation and thanks to your score on my question even less now. – Miguel Perez Feb 02 '23 at 16:00