Scroll behaviour of AndroidX RecyclerView view with NestedScrollView

为君一笑 提交于 2019-12-12 18:22:29

问题


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>

回答1:


use this:

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

instead of this:

app:layout_behavior="@string/appbar_scrolling_view_behavior"



回答2:


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)



来源:https://stackoverflow.com/questions/54573167/scroll-behaviour-of-androidx-recyclerview-view-with-nestedscrollview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!