-----------------------------CoordinatorLayout协调者(父类是ViewGroup)---------------------
layout_anchor 锚点可以加View固定到指定的控件上
layout_anchorGravity 锚点控件的方向,上下左右
layout_behavior 行为
1.导包(support:design)
2.里面放入NestedScrollView(layout_behavior="@string/appbar_scrolling_view_behavior")
3.在NestedScrollView中放入相要的控件(如果是多个控件需要用个ViewGroup来包裹起来)
4.再在NestedScrollView中下面定义一个布局(使用layout_anchor的控件必须是协调者的直接子控件)
app:layout_anchor="@id/XX"
app:layout_anchorGravity="left|Top"
------------------------------AppBarLayout---------------------
AppBarLayout(必须写个协调者里)它必须是CoordinatorLayout的直接子类否则失效
app:layout_scrollFags//它必须设置到第一个AppBarLayout的第一个子控件上
(//下面可以一起使用
1.scroll 一起滚动
2.enterAlways进入时一直可见
3.enterAlwaysCollapsed进入时一直是收起来的效果它必须和minHeight一起使用
4.exitUntilCollapsed 退出会一直收起来,滑动到底部
常用组合:app:layout_scrollFlags="scroll|exitUntilCollapsed" 加minHeight
app:layout_scrollFlags="scroll|enterAlwaysCollapsed" 加minHeight
)
在使用NestedScrollView(layout_behavior="@string/appbar_scrolling_view_behavior")需要定义这句表示行为要配合AppBarLayout
常用事件:
addOffsetChangeListener();//监听AppBarLayout的移动
注意:
要让AppBarLayout和滚动控件一起运动需要设置行为
----------------------------CollapsingToolbarLayout(它必须在AppBarLayout中 是FrameLayout的子类)--------------------------
重要属性:
layout_collapseMode(折叠模式) pin , parallax视差 配合(layout_collapseParallaxMultiplier="0.5")
如何布局:
CoordinatorLayout--->AppBarLayout []--->CollapsingToolbarLayout [layout_scrollFlags]--->(ImageView [layout_collapseMode])+++(Toolbar [layout_collapseMode="pin"])+....
Toolbar
--------------------------Snackbar,FloatingActionButton(它必须用在协调者布局中)---------------------
FloatingActionButton:
属性:
fabSize 设置大小
elevation 立体效果
Snackbar
使用:
Snackbar.make(View,text,len).setAction(text, OnClickListener)//设置点击事件
第一个参数:为Snackbar要添加的View即CoordinatorLayout
它是从下向上顶
--------------------------自定义行为-------------------------------------
1.自定义行为 继承CoordinatorLayout.Behavior
2. 添加构造方法
默认
Context,AttributeSet
2.实现两方法
layoutDependsOn
参数1:父容器
参数2:当前view
参数3:依赖的控件
layoutDependChanged