4

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>
Ramesh R
  • 7,009
  • 4
  • 25
  • 38
suraj s
  • 301
  • 1
  • 3
  • 8
  • 1
    Don't put RecyclerView inside another scrolling view. – Eugen Pechanec Feb 07 '19 at 12:20
  • Possible duplicate of [How to use RecyclerView inside NestedScrollView?](https://stackoverflow.com/questions/31000081/how-to-use-recyclerview-inside-nestedscrollview) – Hamid Reza Feb 07 '19 at 12:26
  • was working in app-compat, not in androidx – suraj s Feb 07 '19 at 12:29
  • @EugenPechanec you can definitely have recyclerviews in other scrolling views if nested scrolling is disabled on the RV. – Brandon McAnsh Aug 25 '19 at 15:17
  • @BrandonMcAnsh I was rather concerned about the recycling aspect of a RecyclerView. ScrollView doesn't recycle its contents. If you put a vertical wrap_content RV in a vertical SV there will be no recycling. The whole view hierarchy will be in memory at all times. A better idea would be to adapt the whole view hierarchy into different item types of a single vertical RV. – Eugen Pechanec Aug 25 '19 at 15:40

2 Answers2

1

use this:

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

instead of this:

app:layout_behavior="@string/appbar_scrolling_view_behavior"
Alireza Noorali
  • 3,129
  • 2
  • 33
  • 80
Rahim
  • 21
  • 7
0

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)

Brandon McAnsh
  • 992
  • 8
  • 18