简体   繁体   English

如何在滚动视图中滚动 RecyclerView

[英]how to scroll RecyclerView in scrollview

在此处输入图片说明

how to scroll all above RecyclerView in scrollview如何在滚动视图中滚动 RecyclerView 上方的所有内容

I have to implement RecyclerView in scrollview show as below code, but not scroll RecyclerView.我必须在滚动视图中实现 RecyclerView 显示如下代码,但不滚动 RecyclerView。

please give answer请给出答案

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

Don't use RecyclerView inside ScrollView .不要在ScrollView使用RecyclerView Use NestedScrollView instead of ScrollView .使用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. NestedScrollView就像ScrollView ,但它支持在新旧版本的 Android 上同时充当嵌套滚动父项和子项。 Nested scrolling is enabled by default.默认情况下启用嵌套滚动。

For Example:例如:

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

Use attribute android:nestedScrollingEnabled="false" for smooth scrolling.使用属性android:nestedScrollingEnabled="false"平滑滚动。

使用 NestedScrollView 而不是滚动视图并设置

recyclerView.setNestedScrollingEnabled(false);

Following code snippet will help you to implement scrolling using ScrollView of RecyclerView以下代码片段将帮助您使用RecyclerView ScrollView实现滚动

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scrollbarSize="3dp"
    android:scrollbarThumbVertical="@drawable/scrollbar_black">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <RelativeLayout
            android:id="@+id/rlFiltersSearchEvent"
            android:layout_width="match_parent"
            android:layout_height="250dp"
            android:background="@drawable/action_bar_gradient">

        </RelativeLayout>

        <android.support.v7.widget.RecyclerView
            android:id="@+id/rvListOfEventsMain"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="@dimen/fab_margin"
            android:layout_below="@+id/rlFiltersSearchEvent"
            android:nestedScrollingEnabled="false"
            android:scrollbars="none" />

    </RelativeLayout>
</ScrollView>

Hope it helps希望它有帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM