How to disable RecyclerView scrolling to make the layout listen its ScrollView parent?

11,320

You could easily achieve it by changing your scroll view into a NestedScrollView and setting recyclerView.setNestedScrollingEnabled(false) Has the highest performance and No need to override the layout manager.

Share:
11,320
Jahir Fiquitiva
Author by

Jahir Fiquitiva

Colombian 🇨🇴 | Creative and Passionate Full Stack Developer

Updated on June 09, 2022

Comments

  • Jahir Fiquitiva
    Jahir Fiquitiva almost 2 years

    I'm trying to put a RecyclerView, inside a ScrollView. But the ScrollView doesn't scrolls and the RecyclerView does but I don't want it to... What can I do?

    I tried with this class https://stackoverflow.com/a/30222721/4864104 and in fact the RecyclerView doesn't scroll anymore, but neither does the ScrollView.

    Any help to make the ScrollView work even with the disabled RecyclerView? Thanks in advance.

    This is my layout:

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:fab="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="jahirfiquitiva.projects.activities.DeveloperActivity">
    
    <include
        android:id="@+id/toolbar"
        layout="@layout/toolbar" />
    
    <ScrollView
        android:id="@+id/osv"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/toolbar"
        android:fillViewport="true"
        android:gravity="center"
        android:overScrollMode="never">
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:padding="10dp">
    
            <ImageView
                android:id="@+id/photoJahir"
                android:layout_width="144dp"
                android:layout_height="144dp"
                android:layout_gravity="center"
                android:gravity="center" />
    
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:lineSpacingMultiplier="1.2"
                android:paddingBottom="@dimen/lists_padding"
                android:paddingTop="@dimen/lists_padding"
                android:text="@string/developer_bio"
                android:textSize="@dimen/abc_text_size_subtitle_material_toolbar" />
    
            <View
                android:layout_width="match_parent"
                android:layout_height="@dimen/dividers_about_section"
                android:alpha="0.3"
                android:background="@color/primary" />
    
            <RecyclerView
                android:id="@+id/buttonsGrid"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:paddingBottom="@dimen/lists_padding"
                android:paddingTop="@dimen/lists_padding" />
    
            <View
                android:layout_width="match_parent"
                android:layout_height="@dimen/dividers_about_section"
                android:alpha="0.3"
                android:background="@color/primary" />
    
            <View
                android:layout_width="match_parent"
                android:layout_height="72dp" />
    
        </LinearLayout>
    
    </ScrollView>