android - 如何在 NestedScrollView 中使用 RecyclerView

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

效果很好。我可以在不滚动父 View 的情况下平滑地滚动 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>

现在我无法平滑地滚动 RecyclerView。 我想要的只是:在不滚动父 View 的情况下平滑滚动 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>

最佳答案

只需启用嵌套滚动即可实现流畅的 ScrollView 。

RecyclerView v = (RecyclerView) findViewById(...);
v.setNestedScrollingEnabled(false);

关于android - 如何在 NestedScrollView 中使用 RecyclerView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44453960/

相关文章:

android - 如何在不更改 android 中的静态变量的情况下创建相同 Activity 的新实例?

android - NestedScrollView 内的 RecyclerView ScrollListener

Android 阻止 Gallery 读取应用程序图像

android - AlarmManager 正在重新创建服务

android - 如何在 RecyclerView 适配器中高亮搜索文本

android - RecyclerView inside nestedscrollview with bottom sheet behavior

java - EditText 在 NestedScrollView 内不可滚动

android - 如何在 Button 的点击事件中打开滑动菜单?

android - flutter 图表 : display value above each point

java - 即使应用程序完全关闭后,如何将按钮的状态(例如按钮的可见性)保存在 RecyclerView 项内?