在Material Design里,CoordinatorLayout通常用来作为顶层视图,来协调处理各个子View之间的动作,从而实现各种动画效果,如Snackbar与FloatingActionButton的配合显示效果,就是以CoordinatorLayout作为根布局来实现的
CoordinatorLayout提供Behaviors接口,子View通过实现Behaviors接口来协调和其它View之间的显示效果,可以这么理解:
CoordinatorLayout让其子View之间互相知道彼此的存在,任意一个子View的状态变化会通过Behaviors通知其它子View,CoordinatorLayout就像一个桥梁,连接不同的View,并使用Behavior处理各个子View之间的通信
效果一:
想实现这样的效果挺简单的,主要是在xml布局文件中进行设置
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat">
android:id="@+id/tb_toolbar"
android:layout_width="match_parent"
android:layout_height&