Nitish Sharma
Nitish Sharma

Reputation: 1

Disable Recycler View's Scrolling Inside NestedScrollView

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools">

    <data>

    </data>

    <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/main"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/bg_new_dashboard_gradient_main"
        android:fitsSystemWindows="true"
        android:orientation="vertical">

        <androidx.appcompat.widget.AppCompatImageView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:scaleType="fitXY"
            android:src="@drawable/ic_new_dashboard_bg_lines"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <androidx.constraintlayout.widget.ConstraintLayout
            android:id="@+id/topToolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingHorizontal="@dimen/siq_20"
            android:paddingTop="@dimen/siq_60"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent">

            <androidx.appcompat.widget.LinearLayoutCompat
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/bg_new_dashboard_wallet_fitcoin"
                android:gravity="center_vertical"
                android:orientation="horizontal"
                android:paddingHorizontal="@dimen/siq_16"
                android:paddingVertical="@dimen/siq_6"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent">

                <androidx.appcompat.widget.AppCompatImageView
                    android:id="@+id/sponsorImg"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:adjustViewBounds="true"
                    android:importantForAccessibility="yes"
                    android:maxWidth="60dp"
                    android:maxHeight="20dp"
                    android:screenReaderFocusable="true"
                    android:src="@drawable/test_logo"
                    tools:tint="@color/primary" />

                <androidx.appcompat.widget.AppCompatImageView
                    android:id="@+id/dropDown"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:layout_marginStart="@dimen/siq_4"
                    android:adjustViewBounds="true"
                    android:importantForAccessibility="yes"
                    android:maxWidth="100dp"
                    android:maxHeight="30dp"
                    android:screenReaderFocusable="true"
                    android:src="@drawable/ic_arrow_down_20"
                    app:tint="#A5A6BB" />

            </androidx.appcompat.widget.LinearLayoutCompat>

            <androidx.appcompat.widget.LinearLayoutCompat
                android:id="@+id/ficoinAndWallet"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/bg_new_dashboard_wallet_fitcoin"
                android:gravity="center_vertical"
                android:paddingHorizontal="@dimen/siq_16"
                android:paddingVertical="@dimen/siq_4"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintTop_toTopOf="parent">

                <androidx.appcompat.widget.AppCompatImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    app:srcCompat="@drawable/ic_wallet_new_blue_20" />

                <View
                    android:id="@+id/walletDidvider"
                    android:layout_width="1dp"
                    android:layout_height="10dp"
                    android:layout_marginStart="@dimen/siq_8"
                    android:layout_marginEnd="@dimen/siq_5"
                    android:background="#F3F3F3"
                    app:layout_constraintTop_toBottomOf="@id/topToolbar" />

                <androidx.appcompat.widget.AppCompatImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    app:srcCompat="@drawable/ic_fitcoin_20" />

                <androidx.appcompat.widget.AppCompatTextView
                    android:id="@+id/earn_reward_label"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:layout_marginStart="@dimen/siq_2"
                    android:fontFamily="@font/inter_bold"
                    android:gravity="center_horizontal"
                    android:text="304"
                    android:textColor="#0F0B28"
                    android:textSize="14sp" />

            </androidx.appcompat.widget.LinearLayoutCompat>
        </androidx.constraintlayout.widget.ConstraintLayout>

        <View
            android:id="@+id/dividerTopToolbar"
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:layout_marginTop="@dimen/siq_16"
            android:background="#1AF0F3F6"
            app:layout_constraintTop_toBottomOf="@id/topToolbar" />

        <androidx.core.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:fillViewport="true"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintTop_toBottomOf="@id/dividerTopToolbar">

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

                <androidx.recyclerview.widget.RecyclerView
                    android:id="@+id/topCarouselRv"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:overScrollMode="never"
                    android:paddingTop="@dimen/siq_6"
                    app:layout_constraintTop_toBottomOf="@id/dividerTopToolbar" />

                <androidx.recyclerview.widget.RecyclerView
                    android:id="@+id/mainContentRv"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_marginTop="@dimen/siq_16"
                    android:background="@drawable/bg_new_dashboard_main_rv"
                    android:orientation="vertical"
                    android:overScrollMode="never"
                    android:paddingTop="@dimen/siq_16"
                    android:paddingBottom="@dimen/siq_70"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintTop_toBottomOf="@id/topCarouselRv"
                    tools:itemCount="50" />

            </LinearLayout>

        </androidx.core.widget.NestedScrollView>

        <ProgressBar
            android:id="@+id/progress"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:indeterminate="true"
            android:visibility="gone"
            android:indeterminateTint="#714FFF"
            android:indeterminateTintMode="src_atop"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <androidx.constraintlayout.widget.ConstraintLayout
            android:id="@+id/errorLayout"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:background="@color/white"
            android:visibility="gone"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/dividerTopToolbar">

            <include
                android:id="@+id/noInternetLayout"
                layout="@layout/layout_no_internet_view"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:visibility="visible"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

        </androidx.constraintlayout.widget.ConstraintLayout>

    </androidx.constraintlayout.widget.ConstraintLayout>
</layout>

I have an XML file with two RecyclerViews inside a NestedScrollView. My goal is to disable the independent scrolling of the RecyclerViews so that when I try to scroll, the entire layout scrolls as a whole. I’ve already added overScrollMode="never", but the mainContentRv still scrolls independently. I’ve also tried setting isNestedScrollingEnabled = false, but that disables the scrolling behavior of all the views entirely. Is there any solution to this?

Upvotes: 0

Views: 30

Answers (1)

danielp
danielp

Reputation: 1

you should set isNestedScrollingEnabled = false on the recyclerview, not on your nestedscrollview

Upvotes: 0

Related Questions