Android 6.0 AppBarLayout+CollapsingToolbarLayout+NestedScrollView简单使用
来源:互联网 发布:双十一数据增长文献 编辑:程序博客网 时间:2024/06/05 18:54
Google发布了新的Android Support Design库,里面包含了几个新的控件,其中就有一个AppBarLayout+CollapsingToolbarLayout+NestedScrollView,它可以实现上拉隐藏toolbar等特效,用起来你会爱上它。
效果图
原理
Android6.0更加注重界面上用户的体验,当用户对界面进行操作,操作系统就会对该行为进行分析,目的就是给用户展示更加合理的界面。那么行为是什么?行为就是Behavior滑动。一般要让整个流程完整走执行下来就需要这些对象。行为产生者、协调者、目标对象、控制对象
可以产生行为的对象:ViewPager RecyclerView NestedScrollView
app:layout_behavior=”@string/appbar_scrolling_view_behavior”
整个是系统定义好的。
CoordinatorLayout协调者布局
AppBarLayout 应用bar
Toolbar操作对象
操作对象的显示控制
AppBarLayout的子布局有5种滚动标识(就是上面代码CollapsingToolbarLayout中配置的app:layout_scrollFlags属性):
1 scroll:将此布局和滚动时间关联。这个标识要设置在其他标识之前,没有这个标识则布局不会滚动且其他标识设置无效。
2 enterAlways:任何向下滚动操作都会使此布局可见。这个标识通常被称为“快速返回”模式。
3 enterAlwaysCollapsed:假设你定义了一个最小高度(minHeight)同时enterAlways也定义了,那么view将在到达这个最小高度的时候开始显示,并且从这个时候开始慢慢展开,当滚动到顶部的时候展开完。
4 exitUntilCollapsed:当你定义了一个minHeight,此布局将在滚动到达这个最小高度的时候折叠。是控制Toolbar在最后固定在顶部
5 snap:当一个滚动事件结束,如果视图是部分可见的,那么它将被滚动到收缩或展开。例如,如果视图只有底部25%显示,它将折叠。相反,如果它的底部75%可见,那么它将完全展开。
直接修改Style来完成Toolbar背景的颜色
Activity布局
ViewPager产生行为
<android.support.v4.view.ViewPager android:id="@+id/vp_shopbook" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginTop="@dimen/dp_10" app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
RecyclerView产生行为
<android.support.v7.widget.RecyclerView android:id="@+id/rv" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#c55" app:layout_behavior="@string/appbar_scrolling_view_behavior" ></android.support.v7.widget.RecyclerView>
NestedScrollView产生行为
<android.support.v4.widget.NestedScrollView android:layout_width="match_parent" android:layout_height="match_parent" android:visibility="gone" app:layout_behavior="@string/appbar_scrolling_view_behavior"> <TextView android:layout_width="match_parent" android:layout_height="match_parent" android:text="@string/content" /></android.support.v4.widget.NestedScrollView>
app:layout_scrollFlags :最小高度有关
exitUntilCollapsed:互动折叠到最小高度后,不再有折叠效果
enterAlwaysCollapsed:需要配置enterAlways,当展开到最小高度后,不再展开,而是底部的Child到达顶部滑动才会完全展开。
当然还有很多,大家可以自行研究一下源码。。。
如果AppBarLayout里面有3个空间,中间的控件没有设置app:layout_scrollFlags滑动,就会出现只能滑动第一个控件的情况,具体可以根据需求来设置,也可以自己测试一下。
如果觉得我的文章对您有用,请点赞。您的支持将鼓励我继续码蛋!
- Android 6.0 AppBarLayout+CollapsingToolbarLayout+NestedScrollView简单使用
- CoordinatorLayout、AppBarLayout、TableLayout、CollapsingToolbarLayout、NestedScrollView的使用
- AppBarLayout+ToolBar+CollapsingToolbarLayout+NestedScrollView
- AppBarLayout、CoordinatorLayout、CollapsingToolbarLayout、NestedScrollView
- CoordinatorLayout,CollapsingToolbarLayout,AppBarLayout简单使用
- CoordinatorLayout,AppBarLayout,CollapsingToolbarLayout,Toolbar,NestedScrollView,RecyclerView结合使用
- CoordinatorLayout、AppBarLayout、 Toolbar、CollapsingToolbarLayout、NestedScrollView 综合使用,详细解析
- Android 6.0 CollapsingToolbarLayout简单使用
- android UI AppBarLayout CollapsingToolbarLayout
- android AppBarLayout,CollapsingToolbarLayout
- CoordinatorLayout,CollapsingToolbarLayout,NestedScrollView的使用
- Material design学习笔记-CoordinatorLayout,NestedScrollView,AppBarLayout,CollapsingToolbarLayout学习
- Material Design风 第二话(CollapsingToolbarLayout+AppBarLayout+NestedScrollView)
- Android Design AppBarLayout、NavigationView、FloatingActionButton、CollapsingToolbarLayout等控件的使用
- Android Material Design(5) CoordinatorLayout,AppBarLayout,Toolbar,CollapsingToolbarLayout的使用
- Android学习系列Toolbar,AppBarLayout,CoordinatorLayout,CollapsingToolbarLayout使用小结
- Android学习系列Toolbar,AppBarLayout,CoordinatorLayout,CollapsingToolbarLayout使用小结
- Android学习系列Toolbar,AppBarLayout,CoordinatorLayout,CollapsingToolbarLayout使用小结
- leetcode 100. Same Tree
- 无人值守自动安装Linux操作系统
- [BZOJ]4552 [TJOI2016] 排序 二分 + 线段树
- Arch 新增用户
- HTML5表单相关新增元素和属性
- Android 6.0 AppBarLayout+CollapsingToolbarLayout+NestedScrollView简单使用
- 生成二维码
- oracle10 数据库中 scott用户被锁与解锁
- 获取积分
- Html5_获取主机名,端口,路径 和 jquery简单使用
- 总结
- 配置(Linux、JDK、Tomcat、nginx)阿里云ecs服务器
- 线程同步之信号量
- 自定义View画太极并转动