带有NestedScrollView的AndroidX RecyclerView视图的滚动行为 [英] Scroll behaviour of AndroidX RecyclerView view with NestedScrollView

查看:153
本文介绍了带有NestedScrollView的AndroidX RecyclerView视图的滚动行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将我的应用程序从appcompat迁移到AndroidX.一切正常,除了我不能同时为androidx.core.widget.NestedScrollViewandroidx.core.widget.NestedScrollView设置一个滚动 androidx.recyclerview.widget.RecyclerView.

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.

我尝试添加

setHasFixedSize(true)
setNestedScrollingEnabled(false)

但是它不起作用.我的XML现在看起来是这样的:

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>

推荐答案

您似乎需要从RecyclerView中删除layout_behavior属性,因为您已经为其禁用了嵌套滚动(并且已经为NestedScrollView设置了该属性)

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)

这篇关于带有NestedScrollView的AndroidX RecyclerView视图的滚动行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆