美文网首页Android-CoordinatorLayout.……
CoordinatorLayout协调布局详解

CoordinatorLayout协调布局详解

作者: 你的益达233 | 来源:发表于2020-11-13 17:37 被阅读0次

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:做折叠效果的

  1. parallax:视差模式,在折叠的时候会有折叠视差效果。一般搭配layout_collapseParallaxMultiplier=“0.5”视差的明显程度be between 0.0 and 1.0.
  2. none:没有任何效果,往上滑动的时候toolbar会首先被固定并推出去。
  3. pin:固定模式,在折叠的时候最后固定在顶端。

示例代码:

/**
 * 结构基本都是最外层是CoordinatorLayout,然后有两个子布局,一个是AppBarLayout,另外一个滑动布局可以是viewpager,RecyclerView,NestedScrollView
 * AppBarLayout用来捕获滑动布局的行为,然后它还有子布局,子布局通过设置layout_scrollFlags来控制该子布局它随着滑动布局该怎么滚。如果不设置layout_scrollFlags,默认就是scroll
 * <android.support.design.widget.CoordinatorLayout
 *                 android:layout_width="match_parent"
 *                 android:layout_height="wrap_content"
 *                 android:background="@color/white">
 *
 *                 <android.support.design.widget.AppBarLayout
 *                     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.support.design.widget.CollapsingToolbarLayout
 *                         android:layout_width="match_parent"
 *                         android:layout_height="wrap_content"
 *                         android:clipChildren="false"
 *                         app:layout_scrollFlags="scroll|exitUntilCollapsed">
 *
 *
 *                         <android.support.v7.widget.RecyclerView
 *                             android:id="@+id/common_recycler"
 *                             android:layout_width="match_parent"
 *                             android:layout_height="match_parent"
 *                             app:layout_collapseMode="pin" />
 *
 *                     </android.support.design.widget.CollapsingToolbarLayout>
 *
 *                     <!--滑动悬停-->
 *                     <android.support.constraint.ConstraintLayout
 *                         android:layout_width="match_parent"
 *                         android:layout_height="wrap_content">
 *
 *                         <com.flyco.tablayout.SlidingTabLayout
 *                             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" />
 *
 *                         <View
 *                             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.support.constraint.ConstraintLayout>
 *
 *
 *                 </android.support.design.widget.AppBarLayout>
 *
 *                 <!--协调联动-->
 *                 <android.support.v4.view.ViewPager
 *                     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" />
 *             </android.support.design.widget.CoordinatorLayout>
 */

参考:https://www.jianshu.com/p/7caa5f4f49bd

相关文章

网友评论

    本文标题:CoordinatorLayout协调布局详解

    本文链接:https://www.haomeiwen.com/subject/igkbbktx.html