Avinash
Avinash

Reputation: 264

Android nestedScrollview And ViewPager not working together

I am developing an app which has a viewPager and it should scroll

enter image description here

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

        <android.support.v4.view.ViewPager
            android:id="@+id/activity_main_viewpager"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#FFA0"/>


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

but viewPager is not visible if i use above code

Upvotes: 3

Views: 6526

Answers (2)

Syed Qasim Ahmed
Syed Qasim Ahmed

Reputation: 1362

I am too late to answer this but I face the same problem.

First Solution To solve this problem is to give fix height to viewpager.

Second Solution Use CollapsingToolbarLayout and redesign layout according to CollapsingToolbarLayout

Upvotes: 4

Hitesh Gehlot
Hitesh Gehlot

Reputation: 1347

You are doing it wrong. This is the correct way:

    <android.support.v4.view.ViewPager
        android:id="@+id/activity_main_viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#FFA0"/>

Fragment layout parent view should be

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

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

Upvotes: 5

Related Questions