suraj s
suraj s

Reputation: 321

Scroll behaviour of AndroidX RecyclerView view with NestedScrollView

I'm migrating my application from appcompat to AndroidX. Everything works except that I am not able to set one scroll for both androidx.core.widget.NestedScrollView and androidx.recyclerview.widget.RecyclerView.

I have tried adding

setHasFixedSize(true)
setNestedScrollingEnabled(false)

but it's not working. My XML now looks this way:

<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView
    android:clipToPadding="false"
    android:id="@+id/scroll"
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:paddingBottom="5dp"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <LinearLayout
        android:background="@color/white"
        android:id="@+id/itenarydays"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:orientation="horizontal">

        <FrameLayout
            android:background="@drawable/roundshape"
            android:layout_gravity="center"
            android:layout_height="56dp"
            android:layout_margin="3dp"
            android:layout_width="56dp"
            android:padding="@dimen/textsise10">

            <ImageView
                android:layout_gravity="center"
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:tint="@color/white"
                app:srcCompat="@drawable/ic_sketch" />
        </FrameLayout>

        <androidx.recyclerview.widget.RecyclerView
            android:animationCache="true"
            android:clipToPadding="false"
            android:id="@+id/list_daycount"
            android:layout_gravity="center"
            android:layout_height="match_parent"
            android:layout_width="wrap_content"
            android:nestedScrollingEnabled="false"
            android:orientation="horizontal"
            android:scrollbars="none"

            app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"></androidx.recyclerview.widget.RecyclerView>


        <FrameLayout
            android:background="@drawable/shape_redround"
            android:id="@+id/framelyt_add"
            android:layout_gravity="center"
            android:layout_height="56dp"
            android:layout_margin="3dp"
            android:layout_width="56dp"
            android:padding="@dimen/textsise10">

            <ImageView
                android:layout_gravity="center"
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:tint="@color/white"
                app:srcCompat="@drawable/ic_plus" />
        </FrameLayout>
    </LinearLayout>

</androidx.core.widget.NestedScrollView>

Upvotes: 4

Views: 3464

Answers (2)

Brandon McAnsh
Brandon McAnsh

Reputation: 1031

It appears that you need to remove the layout_behavior attribute from the RecyclerView since you have nested scrolling disabled for it (and already have it set for the NestedScrollView)

Upvotes: 0

Rahim
Rahim

Reputation: 21

use this:

app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"

instead of this:

app:layout_behavior="@string/appbar_scrolling_view_behavior"

Upvotes: 1

Related Questions