0

I have an app that has a recyclerView and a button at the bottom of the recyclerView.

When I am going down, the button is well displayed at the bottom of the recyclerView, but when I am going up, the button stays displayed at the bottom of the screen, and does not stuck at the bottom of the recyclerView. It takes few scroll-up to make it disappears.

Any idea how to make sure that the button always shows at the bottom of the recyclerView and not staying at the bottom of the screen?

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:bind="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true"
    android:background="@color/brand05">

    <androidx.appcompat.widget.LinearLayoutCompat
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/brand05"
        android:orientation="vertical">

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/list_of_vehicles_rv"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="12dp"
            android:layout_marginEnd="12dp"
            android:scrollbars="none"
            android:alignmentMode="alignBounds"
            android:scrollbarThumbVertical="@color/gainsboro_00"
            android:scrollbarSize="2dp"/>


        <LinearLayout
            android:id="@+id/editVehiclesLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            app:layout_constraintTop_toBottomOf="@id/list_of_vehicles_rv">

            <View
                android:layout_width="match_parent"
                android:layout_height="50dp"/>

            <include layout="@layout/widget_bottom_button"
                android:id="@+id/button_add_vehicle"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginStart="@dimen/cell_padding"
                android:layout_marginEnd="@dimen/cell_padding"
                android:layout_marginBottom="@dimen/cell_padding_bottom" />

            <include layout="@layout/widget_bottom_button"
                android:id="@+id/cancel_remove_vehicle"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:visibility="gone"
                android:layout_marginStart="@dimen/cell_padding"
                android:layout_marginEnd="@dimen/cell_padding"
                android:layout_marginBottom="@dimen/cell_padding_bottom"/>

            <include layout="@layout/widget_bottom_button"
                android:id="@+id/remove_selected_vehicle"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:visibility="gone"
                android:layout_marginStart="@dimen/cell_padding"
                android:layout_marginEnd="@dimen/cell_padding"
                android:layout_marginBottom="@dimen/cell_padding_bottom"/>

        </LinearLayout>

        <include
            android:id="@+id/loading"
            layout="@layout/layout_loading"/>
        
    </androidx.appcompat.widget.LinearLayoutCompat>

</ScrollView>

Any idea how to fix it ?

Zain
  • 37,492
  • 7
  • 60
  • 84
Seb
  • 2,929
  • 4
  • 30
  • 73

1 Answers1

0

The problem happens because when the RecyclerView is scrolled up to the top, the outer ScrollView doesn't scroll along until the RecyclerView reach to the top; and therefore the button keeps showing until that.

To fix this: both the ScrollView & RecyclerView need to scroll simultaneously and this can be fixed by replacing the ScrollView with androidx.core.widget.NestedScrollView which sync nested scrolls together.

This thread would help on the difference between ScrollView & NestedScrollView

Zain
  • 37,492
  • 7
  • 60
  • 84