CollapsingToolbarLayout给我么提供了一个可以折叠的toolbar。效果如下
它是design包里面的组件,使用前需要导入库依赖。compile 'com.android.support:design:25.3.1'
先看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"
tools:context="com.example.appbarlayout.MainActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/barlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#00000000">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collap"
android:layout_width="match_parent"
android:layout_height="match_parent"
app