Android 使用CoordinatorLayout实现滚动标题栏效果的实例

  <?xml version="1.0" encoding="utf-8"?>

  

  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:layout_width="match_parent"

  android:layout_height="300dp"

  android:fitsSystemWindows="true"

  android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

  

  android:id="@+id/collapsing_toolbar"

  android:layout_width="match_parent"

  android:layout_height="match_parent"

  app:contentScrim="?attr/colorPrimary"

  app:expandedTitleMarginEnd="88dp"

  app:expandedTitleMarginStart="66dp"

  app:layout_scrollFlags="scroll|exitUntilCollapsed">

  

  

  android:layout_width="match_parent"

  android:layout_height="match_parent"

  android:scaleType="centerCrop"

  android:src="@drawable/bg_image"

  app:layout_collapseMode="pin"/>

  

  

  android:id="@+id/tb_toolbar"

  android:layout_width="match_parent"

  android:layout_height="?attr/actionBarSize"

  app:layout_collapseMode="pin"

  app:navigationIcon="@android:drawable/ic_dialog_email"

  app:title="Title"/>

  

  

  

  android:id="@+id/rv_data"

  android:layout_width="match_parent"

  android:layout_height="match_parent"

  app:layout_behavior="@string/appbar_scrolling_view_behavior"/>