【问题标题】:RecyclerView inside NestedScrollView inside CoordinatorLayoutCoordinatorLayout 内 NestedScrollView 内的 RecyclerView
【发布时间】:2017-10-16 08:42:13
【问题描述】:

我有这样的布局:

    <?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appBarLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:layout_scrollFlags="scroll|enterAlways"
            />
    </android.support.design.widget.AppBarLayout>

    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        android:layout_margin="20dp">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
            <android.support.v7.widget.AppCompatImageView
                android:layout_width="200dp"
                android:layout_height="200dp"
                android:src="@drawable/avatar_placeholder"
                />
            <android.support.v7.widget.RecyclerView
                android:layout_width="wrap_content"
                android:layout_height="200dp"
                android:layout_marginLeft="20dp"
                android:id="@+id/list"
                android:orientation="horizontal"
                app:layoutManager="android.support.v7.widget.LinearLayoutManager"
                />
        </LinearLayout>
    </android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>

如您所见,其中有CoordinatorLayoutNestedScrollView。而在NestedScrollView 里面有水平的RecyclerView。所以这个布局的行为如下:

可以看出,问题出在RecyclerView。当我向上拖动它时,Toolbar 并没有隐藏。在我拉起ImageView Toolbar 隐藏的同时。如何解决?

【问题讨论】:

  • 工具栏隐藏在图片中吧?

标签: android android-recyclerview toolbar android-coordinatorlayout


【解决方案1】:

您是否在您的回收站上启用了嵌套滚动?

recylcer.nestedScrollingEnabled(true)

我有一个非常相似的问题,但是我的回收器是垂直的,你可以在这里参考我的答案:Here

【讨论】:

  • 简单地添加recyclerView.setNestedScrollingEnabled(true); 并不能解决问题。可能我应该添加更多的东西吗?
  • 请看我提供的例子
  • 我尝试将 OffsetChangeListener 添加到 AppBar,但是当我拖动 RecyclerView 时它不会触发,我认为它的原因是 RecyclerView 方向不同
猜你喜欢
  • 2015-12-03
  • 1970-01-01
  • 1970-01-01
  • 2015-09-15
  • 2017-02-15
  • 2017-05-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多