【问题标题】:Nested Recycler View Scrolling Issue嵌套回收站视图滚动问题
【发布时间】:2017-01-14 21:00:27
【问题描述】:

我在嵌套滚动视图(位于 CoordinatorLayout 内)中使用了 Recycler View:

        <android.support.v4.widget.NestedScrollView
            android:id="@+id/scroll"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <android.support.v7.widget.RecyclerView
                    android:id="@+id/sections_recycler_view_linearlayout"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical" />

            </RelativeLayout>

        </android.support.v4.widget.NestedScrollView>

在上述回收器的适配器中,我使用 setNestedScrollingEnabled 作为 false 以编程方式添加了子回收器视图。

我的问题是: 当我滚动子回收器时,一旦它的滚动完成,父回收器就会滚动到顶部,就好像我再次设置它的适配器一样。我没有添加任何代码来通知适配器或滚动到最顶部的回收站项目或再次设置适配器。我无法弄清楚这种奇怪行为的原因。

任何帮助将不胜感激.. !!!

【问题讨论】:

  • 你为什么需要这个结构?一个单一的回收审查可以做同样的事情。
  • 因为我希望父回收器垂直滚动,而子回收器水平滚动。父回收器与可折叠工具栏一起使用以显示工具栏动画,并且将在运行时决定父回收器视图中有多少子回收器。
  • Child Recycler 在滚动时卡住,即使我删除了 setHasFixedSize 或者即使我将其设置为 true 或 false。
  • 检查一下,这可能会有所帮助,我遇到了类似的问题:stackoverflow.com/questions/36923948/…

标签: android android-recyclerview android-coordinatorlayout android-nestedscrollview


【解决方案1】:

添加到您的父回收站视图:

android:descendantFocusability="blocksDescendants"

【讨论】:

    【解决方案2】:

    简单, 添加

    android:fillViewport="true"
    

    到您的 NestedScrollview,您就可以开始了。

    【讨论】:

      【解决方案3】:

      在收到来自服务器的数据之前,我一直在子回收站视图中显示进度条。一旦我得到数据,我就会填充它。我曾为行数为 2 的子回收器使用交错适配器,因此在填充数据后,我的父回收器的高度发生了变化。

      我将 setHasFixedSize(false) 用于父回收站视图,因为它的高度正在变化,直到现在我还没有看到这个问题。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2023-02-08
        • 1970-01-01
        • 1970-01-01
        • 2016-09-22
        • 2017-01-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多