I want to combine a default horizontal ViewPager with some kind of a vertical ViewPager. My approach would be that the Fragments provided by the horizontal ViewPager, are subclassing the vertical ViewPager.
public class SubWebViewFragment extends Fragment, VerticalViewPager {
}
Thus each Fragment provided by the horizontal ViewPager should at the same time act as a VerticalViewPager, building up some kind of a matrix. In addition I have to have the possibility to go to a certain page in this matrix. E.g. I want to select page 2 of the horizontal ViewPager, and of this page two I want to go to page three of the vertical ViewPager.
// pseudo code
HorizontalViewPager.setCurrentItem(1, true);
activeHorizontalPage.getVerticalViewPager.setCurrentItem(2, true);
I'm a bit lost on how to approach this issue.
I built a solution combining a horizontal viewpager (the parent) with vertical viewpagers (each child). I overrode the following methods on vertical viewpager:
public boolean onInterceptTouchEvent(MotionEvent ev)
public boolean onTouchEvent(MotionEvent ev)
When the user triggers those events on each child, they pass it to the parent. Then, if the event is vertical, the child processes it, otherwise, if the event is horizontal, the parent processes it.
Take a look to my DoubleViewPager library, where I implemented this strategy.
This DoubleViewPager project on GitHub seems to have implemented a simple version of what you're asking for. He has a customized HorizontalViewPager and VerticalViewPager derived from the ViewPager class that allows for the page stack structure you're asking for.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With