I would like to create a ViewPager (with three items) where each of its view is another ViewPager (with two items). User then swipe items like this:
ViewPager1[0] ViewPager2[0]
ViewPager1[0] ViewPager2[1]
ViewPager1[1] ViewPager2[0]
ViewPager1[1] ViewPager2[1]
ViewPager1[2] ViewPager2[0]
ViewPager1[2] ViewPager2[1]
How would that be possible?
I just test this case, you can make it without extra working, below is my demo
The xml is simple, outer
ViewPager
in my main layout and the innerViewPager
in anotherLinearLayout
override canScroll in the parent ViewPager:
Try this:
First create a custom ViewPager class in this way:
The return (boolean) of the method canScroll will tell you if the horizontal gesture to change page for ViewPager needs to be in the right or left border of the fragment(true) or if it works for full fragment screen (false). If you want, for example, that only your first fragment use the right border to move to the next fragment because the first fragment has another horizontal scrolling event, this will be the code to overriding the method canScroll:
The Last Step will be to use your CustomViewPager class in your main class:
and the xml:
I don't understand why don't you just create 1 view pager and make the instantiate item logic to get data from different sources, which would make you reach your goal equally I do not see a case where you need 2
viewpagers
Example
and in the code:
this way you have virtually 2
viewpagers
logic, you may customize it more than that I am just giving you ideasP.S. I coded this here so if there are character case mistakes or spelling mistakes forgive me.
hope this helps, if you get more specific and need more help to add a comment on my answer and I will amend it
I solve this task by creating two custom ViewPager's inheritors. In my case - OuterViewPager and InnerViewPager.
Outer pager starts scroll left only when inner pager on last page. And vice versa.