Android NestedScrollView 滚动不起作用

Android NestedScrollView scroll does not work

标题几乎说明了一切。 我有一个带有 FrameLayout 的 Activity,我在运行时添加了一个片段。片段中的数据显示正常,但我无法滚动。

Activity 的布局是:

    <RelativeLayout android:id="@+id/content_layout" 
 xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_height="match_parent"
tools:context=".MainActivity">

    <android.support.design.widget.CoordinatorLayout
        android:fitsSystemWindows="true"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <android.support.design.widget.CollapsingToolbarLayout
                android:id="@+id/collapsingToolbarLayout"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:layout_scrollFlags="scroll|exitUntilCollapsed">

                <android.support.v7.widget.Toolbar
                    android:id="@+id/toolbar"
                    android:layout_width="match_parent" android:layout_height="?attr/actionBarSize"
                    android:background="?attr/colorPrimary" app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                    app:layout_scrollFlags="scroll|enterAlways" />

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

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

        <FrameLayout android:id="@+id/fl_content" android:layout_below="@id/toolbar"
            android:layout_width="match_parent" android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior" >

            <android.support.v4.widget.NestedScrollView
                android:layout_width="match_parent" android:layout_height="match_parent"/>

        </FrameLayout>

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

</RelativeLayout>

片段的布局是:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical"
android:layout_width="match_parent" android:layout_height="match_parent">

<ImageView android:id="@+id/iv_cover"
    android:layout_width="100dp" android:layout_height="100dp" />

<TextView android:id="@+id/tv_release_artistname"
    android:layout_width="wrap_content" android:layout_height="wrap_content" />

<TextView android:id="@+id/tv_release_albumname"
    android:layout_width="wrap_content" android:layout_height="wrap_content" />

<TextView android:id="@+id/tv_release_year"
    android:layout_width="wrap_content" android:layout_height="wrap_content" />

<TextView android:id="@+id/tv_release_label"
    android:layout_width="wrap_content" android:layout_height="wrap_content" />

<TextView android:id="@+id/tv_release_style"
    android:layout_width="wrap_content" android:layout_height="wrap_content" />

<TextView android:id="@+id/tv_release_notes"
    android:layout_width="wrap_content" android:layout_height="wrap_content" />

您应该使 NestedScrollView 成为 FrameLayout 的父级,然后在 FrameLayout 上添加您的 Fragment

现在,当您在其上添加 Fragment 时,您正在覆盖 FrameLayoutNestedScrollView 的内容。

另外别忘了在切换后的NestedScrollView上加上behaviour