android 协调布局,CoordinatorLayout协调布局详解

AppBarLayout的子布局

layout_scrollFlags: Scrolling View和Child View谁先滚动问题

1、scroll:影响向下滚动(默认不设置的值)

Child View 伴随着滚动事件而滚出或滚进屏幕。

注意两点:

第一点,如果使用了其他值,必定要使用这个值才能起作用;

第二点:如果在这个child View前面的任何其他Child View没有设置这个值,那么这个Child View的设置将失去作用

发生向下滚动是,优先滚动Scrolling View,当优先滚动的一方已经全部滚进屏幕之后,另一方才开始滚动

2、enterAlways : 影响向下滚动

对比scroll和scroll | enterAlways设置,发生向下滚动事件时,前者优先滚动Scrolling View,后者优先滚动Child View,

效果:当优先滚动的一方已经全部滚进屏幕之后,另一方才开始滚动

3、enterAlwaysCollapsed:影响向下滚动

一般:scroll|enterAlways|enterAlwaysCollapsed

child View需设定最小值,即minHeight。

效果:向下滚动时,Child View先向下滚动最小高度值,然后Scrolling View开始滚动,到达边界时,Child View再向下滚动,直至显示完全

4、exitUntilCollapsed:影响向上滚动

这里也有最小高度,即有没有设置minHeight,一般不设置

效果:发生向上滚动时,Child View向上滚动退出直到最小高度,然后Scrolling View开始滚动。一般minHeight不设置,所以它就会完全滚出屏幕

5、snap

Child View滚动比例的一个吸附效果。也就是说,

效果:Child View不会存在局部显示的情况,滚动Child View的部分高度,当我们松开手指时,Child View要么向上全部滚出屏幕,要么向下全部滚进屏幕,有点类似ViewPager的左右滑动

CollapsingToolbarLayout的子布局(这个没用过,暂时不展开)

layout_collapseMode:做折叠效果的

parallax:视差模式,在折叠的时候会有折叠视差效果。一般搭配layout_collapseParallaxMultiplier=“0.5”视差的明显程度be between 0.0 and 1.0.

none:没有任何效果,往上滑动的时候toolbar会首先被固定并推出去。

pin:固定模式,在折叠的时候最后固定在顶端。

示例代码:

/**

* 结构基本都是最外层是CoordinatorLayout,然后有两个子布局,一个是AppBarLayout,另外一个滑动布局可以是viewpager,RecyclerView,NestedScrollView

* AppBarLayout用来捕获滑动布局的行为,然后它还有子布局,子布局通过设置layout_scrollFlags来控制该子布局它随着滑动布局该怎么滚。如果不设置layout_scrollFlags,默认就是scroll

*

* android:layout_width="match_parent"

* android:layout_height="wrap_content"

* android:background="@color/white">

*

*

* android:id="@+id/app_bar_layout"

* android:layout_width="match_parent"

* android:layout_height="wrap_content"

* android:clipChildren="false"

* android:background="@color/white"

* android:orientation="vertical">

*

*

*

* android:layout_width="match_parent"

* android:layout_height="wrap_content"

* android:clipChildren="false"

* app:layout_scrollFlags="scroll|exitUntilCollapsed">

*

*

*

* android:id="@+id/common_recycler"

* android:layout_width="match_parent"

* android:layout_height="match_parent"

* app:layout_collapseMode="pin" />

*

*

*

*

*

* android:layout_width="match_parent"

* android:layout_height="wrap_content">

*

*

* android:id="@+id/stl_ceo_data"

* android:layout_width="match_parent"

* android:layout_height="40dp"

* app:layout_constraintTop_toTopOf="parent"

* app:tl_indicator_color="@color/color_D5100A"

* app:tl_indicator_height="2dp"

* app:tl_indicator_width="21dp"

* app:tl_tab_space_equal="true"

* app:tl_textBold="BOTH"

* app:tl_textSelectColor="@color/color_D5100A"

* app:tl_textUnselectColor="@color/c_33"

* app:tl_textsize="16sp" />

*

*

* android:layout_width="0dp"

* android:layout_height="1px"

* android:layout_marginLeft="16dp"

* android:layout_marginRight="16dp"

* android:background="@color/c_f2efef"

* app:layout_constraintLeft_toLeftOf="parent"

* app:layout_constraintRight_toRightOf="parent"

* app:layout_constraintTop_toBottomOf="@id/stl_ceo_data" />

*

*

*

*

*

*

*

* android:id="@+id/vp_pager_ceo_data"

* android:layout_width="match_parent"

* android:layout_height="match_parent"

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

*

*/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值