1.简介
CoordinatorLayout遵循Material 风格,包含在 support Library中,结合AppbarLayout, CollapsingToolbarLayout等 可 产生各种炫酷的折叠悬浮效果。
- 作为最上层的View
- 作为一个 容器与一个或者多个子View进行交互
2.AppBarLayout
它是继承与LinearLayout的,默认 的 方向 是Vertical
appbarLayout的滑动flag
类型 | 说明 |
---|---|
int SCROLL_FLAG_ENTER_ALWAYS | W((entering) / (scrolling on screen))下拉的时候,这个View也会跟着滑出。 |
int SCROLL_FLAG_ENTER_ALWAYS_COLLAPSED | 另一种enterAlways,但是只显示折叠后的高度。 |
int SCROLL_FLAG_EXIT_UNTIL_COLLAPSED | ((exiting) / (scrolling off screen))上拉的时候,这个View会跟着滑动直到折叠。 |
int SCROLL_FLAG_SCROLL | 这个View将会响应Scroll事件 |
int SCROLL_FLAG_SNAP | 在Scroll滑动事件结束以前 ,如果这个View部分可见,那么这个View会停在最接近当前View的位置 |
我们可以通过两种 方法设置这个Flag
方法一
setScrollFlags(int)
方法二
app:layout_scrollFlags="scroll|enterAlways"
AppBarLayout必须作为CoordinatorLayout的直接子View,否则它的大部分功能将不会生效,如layout_scrollFlags等。
效果图一:
布局:
<android.support.design.widget.CoordinatorLayout
android:id="@+id/main_content"
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.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|ent