Search code examples
androidandroid-listviewandroid-viewpagerandroid-scrollview

ViewPager inside ViewPager.How to scroll parent pager horizontally instead of scrolling child, but keep child pager vertical scroll?


I have a parent ViewPager, each page of which contains a child ViewPager. Child ViewPager may contain a ListView or a vertical ScrollView. I want to pass horizontal scroll from child ViewPager to parent ViewPager, but want to keep child ViewPager scrollable vertical.

Overriding dispatchTouchEvent(MotionEvent event) in child ViewPager and returning false helps to pass motion events to parent ViewPager, but how to keep ListView and ScrollView in child ViewPager scrollable?


Solution

  • The solution was easier than I expected.

    Just override canScrollHorizontally in child ViewPager and return false.