Android - combine horizontal viewer with vertical viewpager

I want to combine the default horizontal ViewPager with some kind of vertical ViewPager >. My approach is that the fragments provided by the horizontal ViewPager subclass the vertical ViewPager.

public class SubWebViewFragment extends Fragment, VerticalViewPager { } 

Thus, each fragment provided by a horizontal ViewPager should at the same time act as a VerticalViewPager, creating some kind of matrix. In addition, I should be able to go to a specific page in this matrix. For instance. I want to select page 2 of the horizontal ViewPager, and on 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 lost a little how to approach this problem.

+6
source share
3 answers

I built a solution combining a horizontal viewpager (parent) with vertical views (each child). I tried the following methods on a vertical viewer:

  • public boolean onInterceptTouchEvent(MotionEvent ev)
  • public boolean onTouchEvent(MotionEvent ev)

When the user fires these events for each child, they pass it to the parent. Then, if the event is vertical, the child process processes it; otherwise, if the event is horizontal, the parent process processes it.

Take a look at my DoubleViewPager library, where I implemented this strategy.

+12
source

This DoubleViewPager project on GitHub seems to have implemented a simple version of what you are asking. It has a configured HorizontalViewPager and a VerticalViewPager derived from the ViewPager class, which allows you to query the structure of the page stack.

+2
source

Do you think that using listview instead of a vertical viewpager also try checking out the Twowayview library

0
source

Source: https://habr.com/ru/post/979571/


All Articles