简体   繁体   中英

how to scroll RecyclerView in scrollview

在此处输入图片说明

how to scroll all above RecyclerView in scrollview

I have to implement RecyclerView in scrollview show as below code, but not scroll 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 . Use NestedScrollView instead of 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.

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.

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

recyclerView.setNestedScrollingEnabled(false);

Following code snippet will help you to implement scrolling using ScrollView of RecyclerView

<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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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