【问题标题】:Recyclerview with endless scrolling in nestedscrollview, triggers onScrolled在nestedscrollview中无限滚动的Recyclerview,触发onScrolled
【发布时间】:2016-05-06 13:13:21
【问题描述】:

我在nestedscrollview 中有recyclerview:

   <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <org.apmem.tools.layouts.FlowLayout
                android:id="@+id/filter_view"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/green_main"
                android:paddingLeft="@dimen/small_horizontal_margin"
                android:paddingRight="@dimen/small_horizontal_margin"
                />

            <android.support.v7.widget.RecyclerView
                app:layout_behavior="@string/appbar_scrolling_view_behavior"
                android:id="@+id/recycler_view"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:clipToPadding="false"
                android:scrollbars="vertical"
                android:paddingTop="@dimen/vertical_margin"/>

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

Recyclerview 有 OnScrollListener 处理从这个例子中获取的无限滚动:https://guides.codepath.com/android/Endless-Scrolling-with-AdapterViews-and-RecyclerView。但是,似乎nestedscrollview 正在触发 onScrolled 方法,因此会立即加载整个项目列表。

问题: 我怎样才能防止这种行为?

注意,一切都与不在nestedscrollview 中的recyclerview 完美配合

【问题讨论】:

  • 你有没有机会让它工作?
  • 很遗憾,我没有足够的时间来全面调查此问题。快速的想法,尝试在使用 OnGlobalLayoutListener 处理所有视图后添加滚动监听器
  • 我所做的是将所有内容作为标题视图放在回收器视图适配器中,以便顶视图与回收器视图一起滚动

标签: android android-recyclerview endlessscroll android-nestedscrollview


【解决方案1】:

尝试在 RecyclerView 上禁用嵌套滚动:

recyclerView.setNestedScrollingEnabled(false);

解决了我的错误嵌套滚动问题。让我知道这是否有帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-09-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-01
    • 2021-04-11
    • 1970-01-01
    相关资源
    最近更新 更多