9

在此处输入图像描述我正在处理一个布局,以便将包含回收器视图的片段的 ViewPager 放置在 Coordinator Layout 的嵌套滚动视图中。

问题是一旦我单击回收器视图,嵌套滚动视图就不起作用..

是否有任何可能的方法来拥有这样的布局也可以滚动

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <LinearLayout
            android:id="@+id/lin"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <ViewPager
                android:id="@+id/view_pager"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />


        </LinearLayout>


    <NestedScrollView>

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/transparent"
        app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <FrameLayout
                android:layout_width="match_parent"
                android:layout_height="190dp"
                android:minHeight="190dp"
                app:layout_collapseMode="parallax" >

                <ViewFlipper
                    android:id="@+id/view_flipper"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">

                    <!--<ImageView
                        android:id="@+id/backdrop"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:adjustViewBounds="true"
                        android:fitsSystemWindows="true"
                        android:scaleType="centerCrop"/>-->

                </ViewFlipper>

            </FrameLayout>

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?actionBarSize"
                app:layout_collapseMode="pin" />

        </android.support.design.widget.CollapsingToolbarLayout>

        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="?actionBarSize"
            android:background="?attr/colorPrimary" />

    </android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
4

2 回答 2

0

不要同时使用「Recycler view View Pager + NestedScrollView + CoordinatorLayout」,去掉 NestedScrollView 就可以了。

 <android.support.design.widget.CoordinatorLayout
    android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fitsSystemWindows="true"
            app:expandedTitleTextAppearance="@android:color/transparent"
            app:layout_collapseParallaxMultiplier="0.7"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:titleEnabled="false">

            <LinearLayout
                android:id="@+id/header_view"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:animateLayoutChanges="true"
                android:fitsSystemWindows="true"
                android:orientation="vertical"
                app:layout_collapseParallaxMultiplier="0.7">

              <..somethings..>

            </LinearLayout>

            <android.support.v7.widget.Toolbar
                android:layout_width="match_parent"
                android:layout_height="48dp"
                android:visibility="invisible"
                app:layout_collapseMode="pin"/>
        </android.support.design.widget.CollapsingToolbarLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:layout_gravity="bottom"
            android:orientation="vertical">

            <View
                android:layout_width="wrap_content"
                android:layout_height="0.4dp"
                android:background="?attr/separate_line_color"/>

            <android.support.design.widget.TabLayout
                android:id="@+id/tablayout_user"
                android:layout_width="match_parent"
                android:layout_height="48dp"
                android:layout_marginEnd="8dp"
                android:layout_marginRight="8dp"

                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/view_line"
                app:layout_scrollFlags="enterAlways"
                app:tabGravity="center"
                android:background="?attr/common_bg_white_black"
                app:tabIndicatorColor="@color/theme_color"
                app:tabIndicatorHeight="2dp"
                app:tabMaxWidth="0dp"
                app:tabMode="fixed"
                app:tabPaddingEnd="20dp"
                app:tabPaddingStart="20dp"
                app:tabSelectedTextColor="@color/theme_color"
                app:tabTextAppearance="@style/TabTextAppearance2"
                app:tabTextColor="?attr/text_color_2"/>

        </LinearLayout>
    </android.support.design.widget.AppBarLayout>

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

</android.support.design.widget.CoordinatorLayout>
于 2017-10-27T08:38:00.087 回答
-3

ViewPager 在 NestedScrollView 中不起作用。您必须将其用作 CoordinatorLayout 的子项。

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

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

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@android:color/transparent"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        app:contentScrim="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="190dp"
            android:minHeight="190dp"
            app:layout_collapseMode="parallax">

            <ViewFlipper
                android:id="@+id/view_flipper"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <!--<ImageView
                    android:id="@+id/backdrop"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:adjustViewBounds="true"
                    android:fitsSystemWindows="true"
                    android:scaleType="centerCrop"/>-->

            </ViewFlipper>

        </FrameLayout>

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?actionBarSize"
            app:layout_collapseMode="pin" />

    </android.support.design.widget.CollapsingToolbarLayout>

    <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="?actionBarSize"
        android:background="?attr/colorPrimary" />

</android.support.design.widget.AppBarLayout>

</android.support.design.widget.CoordinatorLayout>
于 2015-08-22T02:46:10.107 回答