How to Have a Viewpager Inside of a Scrollview

Is it possible to have a ViewPager inside of a ScrollView?

I've figured it out;

I needed to add android:fillViewport="true" to the ScrollView element.

ViewPager inside ScrollView not working

Try adding this piece of code before loading your viewPager

NestedScrollView scrollView = (NestedScrollView) findViewById (R.id.nest_scrollview);
scrollView.setFillViewport (true);

Let me know if it helped fix the issue.

ScrollView Inside ViewPager Not Working

I managed to solve a similar vertical scrolling problem in my ViewPager doing the following:

  1. I created a separate layout (content_event) with ViewPager:

    <RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v4.view.ViewPager
    android:id="@+id/viewPagerActivEvent"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    </android.support.v4.view.ViewPager>

    </RelativeLayout>
  2. And created NestedScrollView enclosing preceding layout with "android:fillViewport" set to true:

    <android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" >

    <include layout="@layout/content_event" >

    </android.support.v4.widget.NestedScrollView>

Maybe it's not quite right but worked for me:)



Related Topics



Leave a reply



Submit