ViewPager inside ViewPager

xpepermint picture xpepermint · Aug 17, 2011 · Viewed 44.6k times · Source

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?

Answer

straya picture straya · Dec 2, 2012

override canScroll in the parent ViewPager:

@Override
protected boolean canScroll(View v, boolean checkV, int dx, int x, int y) {
   if(v != this && v instanceof ViewPager) {
      return true;
   }
   return super.canScroll(v, checkV, dx, x, y);
}