Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 840
Shamil Avatar asked May 25 '20 22:05

Shamil


People also ask

What the difference between ViewPager and ViewPager2?

ViewPager2 is an improved version of the ViewPager library that offers enhanced functionality and addresses common difficulties with using ViewPager . If your app already uses ViewPager , read this page to learn more about migrating to ViewPager2 .

What is ViewPager2 in android?

So a Viewpager is an android widget that is used to navigate from one page to another page by swiping left or right using the same activity. So when we use Viewpager, we can add different layouts in one activity and this can be done by using the fragments. Famous applications like WhatsApp, Snapchat uses Viewpager.


1 Answers

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.

like image 191
Tom3652 Avatar answered Oct 04 '22 13:10

Tom3652