Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Horizontal and Vertical ViewPager together

I have a list of items (custom objects). This is the main list. Each of the item in the list has another list of data (URLS). This is the sublist.

I want to show the data from main-list implemented as a vertical viewpager. So, flipping in vertical direction changes the items from the main list. And for the data in each item in the main-list should have the sublist implemented as a horizontal viewpager. So, if the fling is in the horizontal direction it shows me the items in the sublist corresponding to the item in the main list.

Also, vertical fling to any item in the sublist should be able to take to the next item of the mainlist.

Essentially, I am looking at implementing both direction view-pagers. Implementing view-pager in one direction seems to be pretty straight forward. i.e. FragmentActivity hosting a Fragment and a adapter class implementing a FragmentPagerAdapter. But, how should I go about implementing the above functionality?

I tried playing around with some third-party libraries including DirectionalViewPager (it's deprecated though). I am planning to use GestureListeners and animations together to build this effect.

Any pointers on what could be the best way to approach this problem would be very helpful.

Thanks,

like image 987
droidx Avatar asked Oct 20 '22 15:10

droidx


1 Answers

I built a solution combining a horizontal viewpager (the parent) with vertical viewpagers (each child) on a single view called DoubleViewPager. 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.

like image 69
Julio Gómez Avatar answered Oct 23 '22 10:10

Julio Gómez