Android 如何使RecyclerView上方的布局滚动

Android 如何使RecyclerView上方的布局滚动,android,android-recyclerview,Android,Android Recyclerview,这是我的布局: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_pare

这是我的布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:tools="http://schemas.android.com/tools"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                xmlns:app="http://schemas.android.com/apk/res-auto"
                android:id="@+id/book_root_layout">
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:id="@+id/book_spinner_root">

        <RelativeLayout
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="wrap_content">

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/book_cat_show"
                android:text="@string/show_categories"
                android:layout_alignParentLeft="true"
                android:layout_gravity="left"
                android:ellipsize="end"
                android:maxLines="1"
                android:layout_marginLeft="5dp"
                android:textSize="12sp"
                android:stateListAnimator="@null"
                android:background="@drawable/tagcat_button"
                android:minHeight="0dp"
                android:minWidth="0dp"
                android:padding="7dp"
                android:layout_centerInParent="true"
                android:textColor="@color/white"
                android:textStyle="bold"
                android:layout_marginTop="10dp"
                android:visibility="visible"/>

            <ProgressBar
                android:layout_width="30dp"
                android:layout_height="30dp"
                android:layout_centerInParent="true"
                android:indeterminateTint="@color/colorAccent"
                android:visibility="visible"
                android:id="@+id/book_cat_prog"/>

            <Spinner
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="5dp"
                android:visibility="visible"
                android:id="@+id/book_cat_spinner"
                style="@android:style/Widget.Holo.Light.Spinner"/>
        </RelativeLayout>

        <RelativeLayout
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="wrap_content">

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/book_tag_show"
                android:text="@string/show_tags"
                android:layout_alignParentRight="true"
                android:layout_marginRight="5dp"
                android:stateListAnimator="@null"
                android:maxLines="1"
                android:ellipsize="end"
                android:textSize="12sp"
                android:background="@drawable/tagcat_button"
                android:minHeight="0dp"
                android:minWidth="0dp"
                android:padding="7dp"
                android:layout_centerInParent="true"
                android:textColor="@color/white"
                android:textStyle="bold"
                android:layout_marginTop="10dp"
                android:visibility="visible"/>

            <ProgressBar
                android:layout_width="30dp"
                android:layout_height="30dp"
                android:visibility="visible"
                android:layout_centerInParent="true"
                android:indeterminateTint="@color/colorAccent"
                android:id="@+id/book_tag_prog"/>

            <Spinner
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:visibility="visible"
                android:layout_margin="5dp"
                android:id="@+id/book_tag_spinner"
                style="@android:style/Widget.Holo.Light.Spinner"/>
        </RelativeLayout>
    </LinearLayout>

    <android.support.v4.widget.SwipeRefreshLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/book_spinner_root"
        android:id="@+id/swipe_refrsh">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/book_recycler"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"
            android:scrollbars="vertical"
            android:scrollbarFadeDuration="500"/>
    </android.support.v4.widget.SwipeRefreshLayout>
    <include layout="@layout/loading"/>

</RelativeLayout>

当我滚动recyclerview时,
SwipeRefreshLayout
上方的LinearLayout(book_spinner_root)保持固定在屏幕顶部。但我真正想要的是当我在滚动时滚动的线性布局


请告诉我如何实现这一点?

将整个布局包装在嵌套的滚动视图中

您可以使用
CoordinatorLayout
来实现您想要的滚动效果(在
RecyclerView
scoll之外创建布局)

使用NestedScrollView包装后,尝试RecyclerView.setNestedScrollingEnable(dtrue)