【问题标题】:RecyclerView part of ScrollViewScrollView 的 RecyclerView 部分
【发布时间】:2016-09-10 19:15:28
【问题描述】:

我有一个 RecyclerView 作为底部视图,以及顶部的一些其他视图:

我想滚动整个视图 (1),而不仅仅是 RecyclerView (2)。

我已经设法让它工作了,但并非完美无缺。 XML:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <include layout="@layout/toolbar" />

    <android.support.v4.widget.NestedScrollView
        android:id="@+id/scrollView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

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

            ...

            <View
                style="@style/Divider"
                android:layout_marginBottom="16dp" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:padding="8dp">

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

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

两个问题:

  1. 在 recyclerview 中滚动并不顺畅,因为当我抬起手指时,滚动停止。没有加速滚动,或者你怎么称呼它。

  2. 当我从回收站视图中删除项目时,它的高度保持不变。这意味着我在图像曾经存在的地方有空白空间。

【问题讨论】:

  • 我也有同样的问题,我从服务器获取了recycler的数据,我已经检查过了,recycler不流畅的原因是它在一个滚动视图中并且一次从服务器获取所有图像和不可见的项目!我还没有任何解决方案,你有吗?!

标签: android xml xamarin


【解决方案1】:

我已经尝试过你的例子

recyclerview 中滚动并不顺畅,因为当我 抬起手指,滚动停止。没有加速滚动,或 不管你怎么称呼它。

连我都注意到了。我认为使用嵌套滚动时会有一些限制,因为它必须同时处理两个滚动。

当我从 recyclerview 中删除项目时,它的高度仍然是 相同的。这意味着我在图像曾经存在的地方有空白空间。

空白是因为您已将padding 应用于recyclerviewlinear layout。事件虽然您从 recyclerview 中删除所有项目,但父 linear layout 的填充保持不变,空格也是如此。

【讨论】:

  • 是的,这似乎是一个简单的问题。我将尝试尝试许多其他可用的视图。也许我还需要覆盖一些滚动行为。
  • @raze 是的。那么空白区域呢。是我在回答中解释的情况吗?
  • 不,这没有帮助。即使我有 wrap_content 并删除了填充,视图仍然和图像一样高。需要以某种方式刷新布局。
  • @raze 删除项目后,您是否在recyclerview adapter 上使用过notifyDataSetChanged()?如果没有,请使用它
  • 我使用 NotifyItemRemoved(position)。资源较少,并带有动画。它适用于我拥有的其他回收站视图。
【解决方案2】:

使用嵌套滚动视图

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

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

【讨论】:

  • 但是我得到了不需要的行为。
  • 把它放在RelativeLayout里面而不是LinearLayout里面
  • 如果你确定这可行,你能提供一个完整的布局吗?我现在倒退了:)
猜你喜欢
  • 1970-01-01
  • 2014-10-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多