Adil Saiyad
Adil Saiyad

Reputation: 1592

how to scroll RecyclerView in scrollview

enter image description here

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>

Upvotes: 2

Views: 13954

Answers (3)

Pankaj Lilan
Pankaj Lilan

Reputation: 4453

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

Upvotes: -1

Ferdous Ahamed
Ferdous Ahamed

Reputation: 21766

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.

Upvotes: 15

Gautam Singh
Gautam Singh

Reputation: 37

Use NestedScrollView instead of scroll view and set

recyclerView.setNestedScrollingEnabled(false);

Upvotes: 3

Related Questions