0

I am trying to disable NestedScrollView when my RecyclerView is visible. Below is my layout :

 <RelativeLayout
        android:layout_width="match_parent"
        android:background="@color/colorBackgroundApp"
        android:layout_height="match_parent">

        <androidx.coordinatorlayout.widget.CoordinatorLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true">

            <com.google.android.material.appbar.AppBarLayout
                android:id="@+id/app_bar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:fitsSystemWindows="true"
                android:theme="@style/AppTheme.AppBarOverlay">

                <com.google.android.material.appbar.CollapsingToolbarLayout
                    android:id="@+id/toolbar_layout"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:fitsSystemWindows="true"
                    app:contentScrim="@color/colorPrimary"
                    app:layout_scrollFlags="scroll|exitUntilCollapsed"
                    app:toolbarId="@+id/toolbar">

                    <RelativeLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent">

                        <RelativeLayout
                            android:id="@+id/rl1"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_marginStart="16dp"
                            android:layout_marginEnd="16dp">

                            <LinearLayout
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:layout_alignParentStart="true"
                                android:layout_marginTop="70dp"
                                android:gravity="center"
                                android:orientation="vertical">

                                <TextView
                                    android:id="@+id/tv_class_name"
                                    style="@style/TextAppearance.MdcTypographyStyles.Headline4"
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:text="@string/hey_there"
                                    android:textColor="@android:color/white" />

                                <TextView
                                    android:id="@+id/tv_videos_test"
                                    style="@style/TextAppearance.MdcTypographyStyles.Subtitle1"
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:text="@string/let_s_start_with_finding_you_a_right_property"
                                    android:textColor="@android:color/white"
                                    android:textSize="12sp" />

                            </LinearLayout>

                            <com.google.android.material.card.MaterialCardView
                                android:id="@+id/materialCardView"
                                android:layout_width="50dp"
                                android:layout_height="50dp"
                                android:layout_alignParentEnd="true"
                                android:layout_marginStart="15dp"
                                android:layout_marginTop="20dp"
                                android:theme="@style/Theme.MaterialComponents.Light"
                                android:visibility="gone"
                                app:cardBackgroundColor="#FAFAFB"
                                app:cardCornerRadius="15dp"
                                app:cardElevation="3dp"
                                app:layout_constraintBottom_toBottomOf="parent"
                                app:layout_constraintStart_toStartOf="parent"
                                app:layout_constraintTop_toTopOf="parent">

                                <ImageView
                                    android:layout_width="match_parent"
                                    android:layout_height="match_parent"
                                    android:scaleType="centerCrop"
                                    android:src="@drawable/person_placeholder" />

                            </com.google.android.material.card.MaterialCardView>


                        </RelativeLayout>

                       <!-- <EditText
                            android:id="@+id/locationEditText"
                            android:layout_width="match_parent"
                            android:layout_height="45dp"
                            android:layout_below="@id/rl1"
                            android:layout_marginStart="25dp"
                            android:layout_marginTop="30dp"
                            android:layout_marginEnd="25dp"
                            android:background="@drawable/search_bg"
                            android:drawableEnd="@drawable/ic_baseline_arrow_drop_down_24"
                            android:drawablePadding="10dp"
                            android:ems="12"
                            android:focusable="false"
                            android:fontFamily="@font/montserrat_regular"
                            android:hint="@string/search_properties"
                            android:inputType="text"
                            android:lines="1"
                            android:maxLines="1"
                            android:onClick="@{()->viewModel.onSearchClicked()}"
                            android:paddingStart="16dp"
                            android:textAllCaps="false"
                            android:textColor="@color/colorTextPrimary"
                            android:textColorHint="@color/colorTextSecondary"
                            android:textSize="16sp" />-->


                    </RelativeLayout>

                    <androidx.appcompat.widget.Toolbar
                        android:id="@+id/toolbar"
                        android:layout_width="match_parent"
                        android:layout_height="?attr/actionBarSize"
                        app:layout_collapseMode="pin"
                        app:popupTheme="@style/AppTheme.PopupOverlay">

                        <ImageView
                            android:id="@+id/logoImageView"
                            android:layout_width="30dp"
                            android:layout_height="30dp"
                            android:layout_marginEnd="16dp"
                            android:src="@drawable/logo"/>

                        <TextView
                            android:id="@+id/toolbar_text"
                            style="@style/TextAppearance.MdcTypographyStyles.Headline6"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:text="@string/app_name"
                            android:textColor="@android:color/white"
                            android:visibility="visible" />
                    </androidx.appcompat.widget.Toolbar>


                </com.google.android.material.appbar.CollapsingToolbarLayout>
            </com.google.android.material.appbar.AppBarLayout>


            <androidx.core.widget.NestedScrollView
                android:id="@+id/nestedScrollView"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:layout_behavior="@string/appbar_scrolling_view_behavior">

                <androidx.constraintlayout.widget.ConstraintLayout
                    android:layout_width="match_parent"
                    android:layout_marginTop="30dp"
                    android:layout_height="wrap_content">

                    <EditText
                        android:id="@+id/locationEditText"
                        android:layout_width="match_parent"
                        android:layout_height="45dp"
                        android:background="@drawable/search_bg"
                        android:drawableEnd="@drawable/ic_baseline_arrow_drop_down_24"
                        android:drawablePadding="10dp"
                        android:ems="12"
                        android:layout_marginStart="25dp"
                        android:layout_marginEnd="25dp"
                        android:focusable="false"
                        android:fontFamily="@font/montserrat_regular"
                        android:hint="@string/search_properties"
                        android:inputType="text"
                        android:lines="1"
                        android:maxLines="1"
                        android:onClick="@{()->viewModel.onSearchClicked()}"
                        android:paddingStart="16dp"
                        android:textAllCaps="false"
                        android:textColor="@color/colorTextPrimary"
                        android:textColorHint="@color/colorTextSecondary"
                        android:textSize="16sp"
                        app:layout_constraintEnd_toEndOf="parent"
                        app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintTop_toTopOf="parent" />


                    <FrameLayout
                        android:layout_width="0dp"
                        android:layout_height="300dp"
                        android:translationZ="50dp"
                        app:layout_constraintEnd_toEndOf="@+id/locationEditText"
                        app:layout_constraintStart_toStartOf="@+id/locationEditText"
                        app:layout_constraintTop_toBottomOf="@+id/locationEditText">

                        <androidx.recyclerview.widget.RecyclerView
                            android:id="@+id/recyclerViewCities"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:background="@android:color/white"
                            android:layout_marginStart="10dp"
                            android:layout_marginEnd="10dp"
                            android:visibility="gone" />

                    </FrameLayout>


                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:orientation="vertical"
                        android:layout_marginTop="20dp"
                        app:layout_constraintTop_toBottomOf="@+id/locationEditText">

                        <TextView
                            style="@style/TextAppearance.MdcTypographyStyles.Headline5"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_marginStart="15dp"
                            android:layout_marginEnd="15dp"
                            android:layout_marginBottom="16dp"
                            android:ellipsize="end"
                            android:maxLines="1"
                            android:text="Categories"
                            android:textColor="@android:color/white"
                            android:textSize="18sp" />

                        <androidx.recyclerview.widget.RecyclerView
                            android:id="@+id/recyclerViewCategories"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content" />

                        <androidx.recyclerview.widget.RecyclerView
                            android:id="@+id/recyclerViewHome"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_marginTop="10dp"
                            tools:listitem="@layout/home_category_list" />

                    </LinearLayout>


                </androidx.constraintlayout.widget.ConstraintLayout>



            </androidx.core.widget.NestedScrollView>
        </androidx.coordinatorlayout.widget.CoordinatorLayout>


        <ProgressBar
            android:id="@+id/progressbarHome"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true" />


    </RelativeLayout>

I have recyclerViewCities whose visibility is GONE initially inside NestedScrollView. This recyclerViewCities is shown when edit text is clicked.

I have tried the below code to disable NestedScrollView scrolling when the recyclerViewCities is visible and enable it when its visibility is GONE. But it's not working.

   if (binding.recyclerViewCities.visibility == View.VISIBLE) {
                        binding.recyclerViewCities.visibility = View.GONE
                        binding.nestedScrollView.isNestedScrollingEnabled = true
                    } else {
                        binding.recyclerViewCities.visibility = View.VISIBLE
                        binding.nestedScrollView.isNestedScrollingEnabled = false
                    }

Am I missing something? How to disable nestedScrollView scrolling when recyclerview is visible and vise-versa?

5
  • Where do you run the VISIBLE - GONE function? Commented Oct 31, 2023 at 14:39
  • It's called when edit text is clicked. Commented Oct 31, 2023 at 16:00
  • binding.root.requestLayout() or .invalidate() can you try Commented Oct 31, 2023 at 16:32
  • Where to keep this code? Commented Nov 1, 2023 at 8:10
  • You can add it at the end of the if block Commented Nov 1, 2023 at 8:24

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.