【问题标题】:So whats the verdict on NestedScrollView and Recyclerview used together?那么 NestedScrollView 和 Recyclerview 一起使用的结果是什么?
【发布时间】:2017-09-24 08:09:11
【问题描述】:

当我试图围绕 Google 在他们的开发者社区支持中使用的逻辑围绕我的大脑时,它让我发疯了,以至于我不得不开始拔头发(幸运的是我是秃头)。 我的意思是,人们会期望谷歌间接提倡的小部件 NSV 作为其根容器,可以与其他几乎普遍使用的小部件 recyclerview 一起使用。

他们怎么没有想到这一点,我无法理解。在 API22 让我们感到困惑之后,谷歌仍然没有解决它们之间的问题。

对于浪费时间的非生产性咆哮,我深表歉意。

我有什么
我想这里没有什么新东西,因为几乎每个在nestedscrollview 中挣扎的人都得到了和我一样的设置。但是为了完整起见,这是脚手架我的观点。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical">
    <android.support.design.widget.CoordinatorLayout 
        tools:ignore="RtlHardcoded">

        <android.support.design.widget.AppBarLayout
            >

            <android.support.design.widget.CollapsingToolbarLayout
            >


                <View
                    ></View>

                <android.support.v7.widget.Toolbar
                    android:id="@id/tool_bar"
                     />
            </android.support.design.widget.CollapsingToolbarLayout>
        </android.support.design.widget.AppBarLayout>


        <android.support.v4.widget.NestedScrollView
            app:layout_behavior="@string/appbar_scrolling_view_behavior"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            <LinearLayout
                android:orientation="vertical"
                android:layout_width="match_parent"
                android:layout_height="match_parent">
            <TextView
                android:layout_width="match_parent"
                android:layout_height="100dp" />
            <android.support.v7.widget.RecyclerView
                android:layout_width="match_parent"
                android:layout_height="match_parent"></android.support.v7.widget.RecyclerView>
            </LinearLayout>
        </android.support.v4.widget.NestedScrollView>

        <com.roughike.bottombar.BottomBar
            android:id="@+id/bottom_navigation_bar"
            />
    </android.support.design.widget.CoordinatorLayout>
</LinearLayout>

问题 简单的 ! .房车应该围。它应该在被抛出时抛出,在停止时停止。在 NSV 的 viel 下,虽然 RV 没有甩动,但手指一抬起它就停止了。

推测
我可以支配这么短的时间(客户总是这样),并且在滚动期间可能涉及 recyclerview 和 nsv 之间的残酷技术性,我真的没有太大的动力去拿蜡烛并走进下面的阴影。

然而,我用完了选项并控制+单击了 RV。有人说这个问题与布局管理器有关。

如果我希望提出解决方案,我会在这里发布。如果您对此事有任何想法,请在此处发表您的想法。

【问题讨论】:

    标签: android android-recyclerview material-design android-nestedscrollview


    【解决方案1】:

    我在 recyclerview 上遇到过同样的问题。 将此值设置为 falsev(我不知道确切的方法名称)

    RV.setHasFixedSize(假)

    【讨论】:

    • recyclerView.setHasFixedSize(false);我按照你的建议试过了。工作它没有。 :|
    • 你添加了nestedScrollingEnabled = true 吗?
    • nestedscrollingenabled 是一种非常糟糕的方法。它在 RV 中加载完整的数据集并终止回收。如果我在数据集中有一千行,它将加载所有行。这也会导致无限滚动的问题。不幸的是,它不是一个选择
    【解决方案2】:

    我猜你正面临这个问题,因为你在 NSV 中使用 RV。

    只需将 RV 用作 -

    .......
    
                </android.support.design.widget.AppBarLayout>
    
    
                            <LinearLayout
                                android:orientation="vertical"
                                android:layout_width="match_parent"
                                android:layout_height="match_parent">
                            <TextView
                                android:layout_width="match_parent"
                                android:layout_height="100dp" />
                            <android.support.v7.widget.RecyclerView
                        app:layout_behavior="@string/appbar_scrolling_view_behavior"
                                android:layout_width="match_parent"
                                android:layout_height="match_parent">
    </android.support.v7.widget.RecyclerView>
                            </LinearLayout>
    

    在 RV 中使用 app:layout_behavior="@string/appbar_scrolling_view_behavior" 可能会解决您的问题。

    【讨论】:

    • 如果我使用它,我会遇到一个小问题。 LinearLayout 内的 TV 和 RV 不会在其容器内向上滚动。这实际上是根据设计的要求。 textview 和 NSV 的底部之间存在一些空间。拖动后,该空间将被填满,并且 RV 应开始滚动。
    • 如果你在 LinearLayout 中移动 app:layout_behavior="@string/appbar_scrolling_view_behavior" 比。 TextView 将移动直到您的工具栏隐藏并在顶部保持可见......并且 RV 将正常滚动。但是,如果您希望 Textview 也应该隐藏在 RV 滚动上,而不是让 Textview 成为 RV 的一部分。
    • 这似乎是一个合理的建议。给我一点时间来测试一下。
    • 部分。无论如何,我实际上都必须使用 NSV。我在 NSV 容器中可能有 5 个视图,其中一个是 RV。我能做的就是听取你的建议,让所有其他视图成为 RV 的一部分。这将是一项繁琐的工作。还需要更改适配器。我仍然在这里等待其他一些建议。如果我没有得到它们,我会将其标记为正确。
    猜你喜欢
    • 2011-03-09
    • 1970-01-01
    • 2019-09-19
    • 1970-01-01
    • 1970-01-01
    • 2018-02-14
    • 1970-01-01
    • 2014-10-05
    • 1970-01-01
    相关资源
    最近更新 更多