简体   繁体   中英

RecyclerView inside NestedScrollView inside CoordinatorLayout

I have such layout:

    <?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>

As you can see there are CoordinatorLayout with NestedScrollView inside it. And inside of the NestedScrollView there are horizontal RecyclerView . So this layout behaves as follows: 如下

As one can see, problem is in RecyclerView . When I drag it up, Toolbar doesn't hide. In the same time when I dragging up the ImageView Toolbar hides. How to fix that?

did you enable nested scrolling on your recycler ?

recylcer.nestedScrollingEnabled(true)

I had a pretty similar problem, but my recycler was vertical, you can refer to my answer here : Here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM