android - 如何在 ScrollView 中滚动 RecyclerView

标签 android xml android-recyclerview scrollview

enter image description here

如何在scrollview中滚动所有RecyclerView上方

我必须在 ScrollView 中实现 RecyclerView,如下代码所示,但不能滚动 RecyclerView。

请回答

            <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@+id/horizontalScrollView"
            android:layout_marginTop="10dp">

          <RelativeLayout...

                        <android.support.v7.widget.RecyclerView
                            android:id="@+id/rvpouch"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:nestedScrollingEnabled="false"
                            android:layout_below="@+id/textView3">


                        </android.support.v7.widget.RecyclerView>

                    </RelativeLayout>

        </ScrollView>

最佳答案

不要在 ScrollView 中使用 RecyclerView。使用 NestedScrollView 而不是 ScrollView

NestedScrollView is just like ScrollView, but it supports acting as both a nested scrolling parent and child on both new and old versions of Android. Nested scrolling is enabled by default.

例如:

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

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

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recyclerView_one"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:nestedScrollingEnabled="false">

        </android.support.v7.widget.RecyclerView>

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recyclerView_two"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:nestedScrollingEnabled="false">

        </android.support.v7.widget.RecyclerView>

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recyclerView_three"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:nestedScrollingEnabled="false">

        </android.support.v7.widget.RecyclerView>

    </LinearLayout>
</android.support.v4.widget.NestedScrollView>

使用属性 android:nestedScrollingEnabled="false" 实现平滑滚动。

关于android - 如何在 ScrollView 中滚动 RecyclerView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44878863/

相关文章:

android - 何时使用约束布局以及如何有效地使用它?

C# - 从 XML 文档中的特定标记获取值

android - RecyclerView 不显示任何图像

android - 如何使用字符串值从适配器中的Mysql设置imageview

java - 无法将数据从 AppCompatDialogFragment 传递到 Fragment (NullPointerException)

android - Flutter oneSignal 通知图标未设置

javascript - 单击输入字段触发窗口调整大小

c# - 序列化 List<T> 错误反射(reflect)字段

xml - 任何类型的外部 IDML 查看器

android - 开始删除文本时如何启用我的搜索方法