简体   繁体   中英

Viewpager inside CoordinatorLayout not scrolling

I want to scroll contents in fragmnets within viewpager. I've searched a lot but I can't find out a solution. for example i tested nestedScrollingEnabled, app:layout_behavior="@string/appbar_scrolling_view_behavior",....

This is my current code

<android.support.design.widget.CoordinatorLayout >
    <android.support.design.widget.AppBarLayout
     >
        <android.support.design.widget.CollapsingToolbarLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:expandedTitleTextAppearance="@android:color/transparent"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">
            <ImageView
                ... />
            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:gravity="center"
                    android:orientation="horizontal">
                  //  content
                </LinearLayout>
            </android.support.v7.widget.Toolbar>
        </android.support.design.widget.CollapsingToolbarLayout>
    </android.support.design.widget.AppBarLayout>

    <android.support.v4.widget.NestedScrollView
        android:id="@+id/nest_scrollview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clipToPadding="false"
        android:fillViewport="true"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">
        <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginBottom="6dp"
            app:cardElevation="5dp"
            app:cardUseCompatPadding="true">

            <LinearLayout
               >
//There is some LinearLayout and then :

                <android.support.design.widget.TabLayout
                    android:id="@+id/tab_layout"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    app:tabTextAppearance="@style/tab_text"
                    />
                <android.support.v4.view.ViewPager
                    android:id="@+id/pager"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                 app:layout_behavior="@string/appbar_scrolling_view_behavior"
                    >
                </android.support.v4.view.ViewPager>
            </LinearLayout>
        </android.support.v7.widget.CardView>
    </android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>

I really appreciate any help you can provide.

I used a scrollview for every fragmnet at first and I added nestedScrollingEnabled=true and it works

 <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:nestedScrollingEnabled="true"
        android:fillViewport="true">

add this line android:nestedScrollingEnabled="true" to ViewPager

<android.support.v4.view.ViewPager
                android:nestedScrollingEnabled="true"
                android:layout_below="@id/tabLayout"
                android:id="@+id/viewpager"
                android:layout_width="match_parent"
                android:layout_height="match_parent">
            </android.support.v4.view.ViewPager>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM