Android 与RecyclerView协调布局

Android 与RecyclerView协调布局,android,android-recyclerview,android-coordinatorlayout,Android,Android Recyclerview,Android Coordinatorlayout,当我在RecyclerView上滚动时,我想隐藏一个线性布局,当我向下滚动时,它会重新出现;其行为应该与工具栏隐藏和重新显示的方式相同 这就是我到目前为止所做的: <android.support.design.widget.CoordinatorLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <LinearLayout

当我在RecyclerView上滚动时,我想隐藏一个线性布局,当我向下滚动时,它会重新出现;其行为应该与工具栏隐藏和重新显示的方式相同

这就是我到目前为止所做的:

<android.support.design.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

   <LinearLayout
        android:id="@+id/viewToHideOnScroll
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <!-- other stuff inside the LinearLayout -->

   </LinearLayout>

   <RecyclerView
        android:id="@+id/recyclerView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

</android.support.design.widget.CoordinatorLayout>
有人能给我一个提示吗,还是我做错了


我一直在关注

您必须将LinearLayout放入AppBar布局中当用户滚动您的线性布局时,您必须创建如下所示的xml文件

 <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/main_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

     <LinearLayout
                android:id="@+id/lytSearchBar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/colorPrimary"
                android:gravity="center_vertical"
                android:orientation="horizontal"
                android:padding="@dimen/fivedp"
                app:layout_scrollFlags="scroll|enterAlways" // layout_scrollFlags for scroll layout
                android:visibility="visible">

     </LinearLayout>
     </android.support.design.widget.AppBarLayout>

      <android.support.v7.widget.RecyclerView
            android:id="@+id/rvOrderList"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@id/lytSearchBar"
            android:paddingTop="@dimen/tendp"
            app:layout_behavior="@string/appbar_scrolling_view_behavior" />

在RecyclerView中,不要忘记添加属性app:layout\u behavior,如上面的xml所示

 <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/main_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

     <LinearLayout
                android:id="@+id/lytSearchBar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/colorPrimary"
                android:gravity="center_vertical"
                android:orientation="horizontal"
                android:padding="@dimen/fivedp"
                app:layout_scrollFlags="scroll|enterAlways" // layout_scrollFlags for scroll layout
                android:visibility="visible">

     </LinearLayout>
     </android.support.design.widget.AppBarLayout>

      <android.support.v7.widget.RecyclerView
            android:id="@+id/rvOrderList"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@id/lytSearchBar"
            android:paddingTop="@dimen/tendp"
            app:layout_behavior="@string/appbar_scrolling_view_behavior" />