How to scroll ViewPager both horizontally and vertically in Android?
<p>I have a ViewPager whose contents are determined runtime. The content size might be more than the screen dimensions, so I thought of having the ViewPager inside a NestedScrollView (which enables vertical scroll) which is inside a HorizontalScrollView (which enables horizontal scroll). This solves the problem of fitting the content, but I am unable to scroll through the ViewPager tabs - possibly ViewPager is not receiving the horizontal scrolls anymore. </p>

<p>For example, in a scenario when content width is more than screen width, my initial scroll should first scroll to the end of content's edges - and then the new content from the FragmentAdapter should be loaded. But with nested scrollview approach, I am unable to load next item from the FragmentAdapter.</p>

<p>My code :</p>

<pre><code>&lt;HorizontalScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"&gt;

    &lt;android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"&gt;

        &lt;RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"&gt;

            &lt;android.support.v4.view.ViewPager
                android:layout_width="match_parent"
                android:layout_height="wrap_content" /&gt;

        &lt;/RelativeLayout&gt;

    &lt;/android.support.v4.widget.NestedScrollView&gt;
&lt;/HorizontalScrollView&gt;
</code></pre>

<p>There is one alternative to this approach. Drop the outer HorizontalScrollView and put the content of ViewPager's FragmentAdapter in a HorizontalScrollView. I am yet to try this solution - but this would lead me to change and retest all my existing layout files for the FragmentAdapter.</p>