首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >在NestedScrollView中使用RecyclerView将为所有项调用onBindView

在NestedScrollView中使用RecyclerView将为所有项调用onBindView
EN

Stack Overflow用户
提问于 2018-06-02 17:55:52
回答 2查看 4.6K关注 0票数 25

我在一个LinearLayout中垂直放置了两个RecyclerViews。我需要让它们都可以滚动,这就是为什么我把LinearLayout放在NestedScrollView里面的原因

这是我的布局文件。

代码语言:javascript
复制
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:scrollbars="none">

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

    <android.support.v7.widget.RecyclerView
        android:id="@+id/featured_list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <android.support.v7.widget.RecyclerView
        android:id="@+id/all_topic_list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
</LinearLayout>

此外,我还禁用了Java代码中的嵌套滚动。

代码语言:javascript
复制
disableNestedScrolling(findViewById(R.id.all_topic_list));
disableNestedScrolling(findViewById(R.id.featured_list));

我的RecylerView库版本是26.1.0

这可以很好地工作,但随后将为列表中的所有项调用onBindViewHolder方法。理想情况下,应该只为列表中的可见项调用它。

我认为这个问题的发生是因为我将wrap_content提供给了RecyclerView。许多关于this问题的答案表明这个问题在v23.2.1中已经解决了,但我已经在使用v26.1.0了。如何解决这个问题?

EN

回答 2

Stack Overflow用户

发布于 2020-05-27 22:02:43

RecyclerView:1.2.0-alpha04开始,我们可以使用ConcatAdapter来解决这个问题https://developer.android.com/reference/androidx/recyclerview/widget/ConcatAdapter

票数 1
EN

Stack Overflow用户

发布于 2018-06-02 18:04:04

将此添加到嵌套滚动视图android:fillViewport="false"

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50655664

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档