如何在NestedScrollView中使用RecyclerView

TOP*_*TOP 5 android android-recyclerview android-nestedscrollview

我有这个布局:

 <android.support.v4.widget.NestedScrollView
    android:id="@+id/scrollview"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

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

            <--There is some layouts here-->
            <RecyclerView
                android:id="@+id/recycler_view"
                android:layout_width="match_parent"
                android:layout_height="match_parent"/>
    </LinearLayout>

</android.support.v4.widget.NestedScrollView>
Run Code Online (Sandbox Code Playgroud)

它运作良好.我可以RecyclerView平滑滚动而无需滚动父视图.

现在我必须把RecyclerView内部放在这样一个FrameLayout:

 <android.support.v4.widget.NestedScrollView
    android:id="@+id/scrollview"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:id="@+id/content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
 <--There is some layouts here-->
        <FrameLayout
            android:id="@+id/review_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <RecyclerView
                android:id="@+id/recycler_view"
                android:layout_width="match_parent"
                android:layout_height="match_parent"/>

            <include
                android:id="@+id/empty_view"
                layout="@layout/review_empty_view"
                android:visibility="gone" />
        </FrameLayout>
    </LinearLayout>

</android.support.v4.widget.NestedScrollView>
Run Code Online (Sandbox Code Playgroud)

现在我无法RecyclerView顺利滚动.我想要的是:RecyclerView平滑滚动而不滚动父视图.我该怎么办?

编辑:这是我的review_empty布局:

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:orientation="horizontal"
    android:padding="16dp">

    <ImageView
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:src="@drawable/shopping_review_empty" />

    <android.support.v4.widget.Space
        android:layout_width="32dp"
        android:layout_height="0dp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/shopping_no_review_message" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

小智 1

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

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

    <FrameLayout
        android:id="@+id/review_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
       <ScrollView
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:layout_weight="1" >
    <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
        <RecyclerView
            android:id="@+id/recycler_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>
            </LinearLayout>
            </ScrollView>
        <include
            android:id="@+id/empty_view"
            layout="@layout/review_empty_view"
            android:visibility="gone" />
    </FrameLayout>
</LinearLayout>

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

尝试这个...