首先是布局
CoordinatorLayout嵌套AppBarLayout,滚动的头部都应该放在AppBarLayout里面,并使用app:layout_scrollFlags="scroll",
下面跟随滚动的使用app:layout_behavior="@string/appbar_scrolling_view_behavior"
代码如下:
<android.support.design.widget.CoordinatorLayout android:id="@+id/coordinator" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/title_bar"> <android.support.design.widget.AppBarLayout android:id="@+id/appBarLayout" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/gray_bg" android:elevation="@dimen/dp_0" app:elevation="0dp"> <LinearLayout android:id="@+id/headerLayout" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="@dimen/dp_4" app:layout_scrollFlags="scroll"> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <LinearLayout android:id="@+id/no_container" android:layout_width="match_parent" android:layout_height="wrap_content"