AppBarLayout 具有滚动行为替代/滚动时粘性视图/大高度 AppBarLayout 导致奇怪的滚动

Rin*_*nov 6 android android-recyclerview android-coordinatorlayout android-appbarlayout android-viewpager2

我当前状态的视频,以便更好地了解我的情况:
\n视频
\RecyclerView 上面的所有内容都在 AppbarLayout 内

\n

具有类似行为的 Reddit 应用示例:
\n视频

\n

目标:
\n1-实现滚动屏幕,视图按从上到下的顺序排列

\n
a)[several views that need to scroll top until gone, their combined height is several screen sizes]  \nb)[view that scrolls until it reaches screen top and then sticks there]  \nc)[Recy\xd1\x81lerView that scrolls beneath view that sticks on screens top] or [ViewPager with fragments containing RecyclerViews]\n
Run Code Online (Sandbox Code Playgroud)\n

RecyclerView2-需要它与并ViewPager包含fragments包含一起工作RecyclerViews

\n

3-保留RecyclerViews回收。

\n

到目前为止我的解决方案:

\n

协调器布局,AppBarLayout 与appbar_scrolling_view_behaviorscroll|exitUntilCollapsed
\n基本上将上面的所有视图视为RecyclerViewAppBarLayout设置属性scroll|exitUntilCollapsed为需要滚动的视图,而不为需要粘贴的视图设置任何滚动属性。

\n

解释:

\n

我想使用RecyclerViewwithmultiple view types并将viewsin 组ab上面视为不同的ViewHolders,并将它们放置在0和提供给1的索引处。listRecyclerView

\n

但没有找到任何关于如何在ViewHolder保留其可点击性(交互性)的同时粘在屏幕顶部的解决方案。所有的解决方案只是画一个view你无论如何都无法交流的..

\n

匆忙中我使用了CoordinatorLayoutwithAppBarLayout和 setscroll behaviorscroll flags

\n

问题:

\n

AppBar当初始滚动手势发生在子视图(RecyclerViewRecyclerView内部)中或以相反顺序发生在内部和第二个滚动手势时,滚动体验非常奇怪,滞后且抖动ViewPager

\n

如果找到自定义行为实现并且它消除了抖动,但滚动体验仍然存在一些不一致。

\n

问题:
\n我并不是询问如何修复当前解决方案中的滚动问题。我确信没有解决方案,因为可能一开始AppbarLayout就不应该有整个屏幕。height所以我没有发布强调滚动错误的视频。

\n

我可以完全放弃 CoordinatorLayout 使用 AppBarLayout 并实现预期的滚动行为吗?\n我花了几个小时(如果不是几天)寻找实现此 T_T 的方法。
\n如果您需要更多信息,请告诉我。

\n

Mar*_*ler 0

Reddit 应用程序表现不同的原因是它似乎使用WebView; 这是 CSS 滚动行为。但可以同样嵌套 XML 或 Compose 组件。这可能不会包含在 中AppBarLayout,但肯定嵌套在 的实际内容区域中ViewPager2

假设这样的结构:

Fragment
    ViewPager2

        Fragment
            CoordinatorLayout
                AppBarLayout <-- maybe, maybe not
                    CollapsingToolbarLayout <-- most definitely
                        Toolbar
                    NestedScrollView <-- scroll happens here
                        RecylerView
Run Code Online (Sandbox Code Playgroud)

NestedScrollView app:layout_behavior和控制 this 的滚动标志CollapsingToolbarLayout。我不确定AppBarLayout那里是否需要 an ,因为CollapsingToolbarLayout位于 package 中appbar。请考虑这两种可能性。包裹着什么NestedScrollView(不是父级Fragment,它所在的父ViewPager2级)很重要。