CoordinatorLayout中的Viewpager无法滚动

时间:2018-07-21 11:18:45

标签: android android-viewpager android-collapsingtoolbarlayout

我想在viewpager中滚动fragmnets中的内容。 我已经搜索了很多,但找不到解决方案。例如我测试了nestedScrollingEnabled,app:layout_behavior =“ @ string / appbar_scrolling_view_behavior”,....

这是我当前的代码

<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>

非常感谢您能提供的任何帮助。

2 个答案:

答案 0 :(得分:1)

将此行android:nestedScrollingEnabled =“ true”添加到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>

答案 1 :(得分:0)

我最初对每个fragmnet使用一个scrollview,并添加了nestedScrollingEnabled = true 而且有效

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