01 相关概念
CoordinateLayout
AppbarLayout
属性 layout_scrollFlags
behavior
02 相关代码
布局文件activity_coordinate_layout_demo.xml
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.youyou.demo_ui.CoordinateLayoutDemoActivity">
<!--appbarlayout里边的东西可以隐藏 -->
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="match_parent"
android:layout_height="200dp"
android:scaleType="fitCenter"
android:src="@drawable/account_head_default"
app:layout_scrollFlags="scroll" />
<TextView
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginTop="@dimen/dp_size_10"
android:gravity="center"
android:text="设置标题"
android:textAlignment="center"
android:textSize="20sp" />
</android.support.design.widget.AppBarLayout>
<!--设置layout behavior让可以滑动的控件和scrollview联动 -->
<!-- scrollview不行 nestedScrollview可以 为啥? -->
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="400dp"
android:background="@color/green_weixin_btn">
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="400dp"
android:background="@color/grey">
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="400dp"
android:background="@color/green_4DC0A4">
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="400dp"
android:background="@color/grey">
</LinearLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
界面效果: