CoordinatorLayout结合AppBarLayout
来源:互联网 发布:教育网络管理系统 编辑:程序博客网 时间:2024/06/05 17:48
效果图
当我们向上滑动的时候隐藏ToolBar,向下滑动的时候显示ToolBar
实现
<android.support.design.widget.CoordinatorLayout 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:background="#00ff99" android:layout_width="match_parent" android:layout_height="wrap_content"> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:background="#00ff00" android:elevation="4dp" android:theme="@style/ThemeOverlay.AppCompat.ActionBar" app:popupTheme="@style/ThemeOverlay.AppCompat.Light" app:layout_scrollFlags="scroll|enterAlways" ></android.support.v7.widget.Toolbar> </android.support.design.widget.AppBarLayout> <android.support.v7.widget.RecyclerView android:id="@+id/recview" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior" ></android.support.v7.widget.RecyclerView> <android.support.design.widget.FloatingActionButton android:layout_width="wrap_content" android:layout_height="wrap_content" app:fabSize="normal" android:src="@drawable/ym1" android:layout_gravity="bottom|end" /></android.support.design.widget.CoordinatorLayout>
根布局我们使用CoordinatorLayout,CoordinatorLayout是一个增强型的FrameLayout。它的作用有两个
- 作为一个布局的根布局
- 作为一个为子视图之间相互协调手势效果的一个协调布局
AppBarLayout 是继承LinerLayout实现的一个ViewGroup容器组件,它是为了Material Design设计的App Bar,支持手势滑动操作。
默认的AppBarLayout是垂直方向的,它的作用是把AppBarLayout包裹的内容都作为AppBar。
为了达到上面效果图的手势动画效果,我们必须做如下设置,通过app:layout_scrollFlags=”scroll|enterAlways” 属性来确定哪个组件是可滑动的
设置的layout_scrollFlags有如下几种选项:
- scroll: 所有想滚动出屏幕的view都需要设置这个flag- 没有设置这个flag的view将被固定在屏幕顶部
- enterAlways: 这个flag让任意向下的滚动都会导致该view变为可见,启用快速“返回模式”。
enterAlwaysCollapsed: 当你的视图已经设置minHeight属性又使用此标志时,你的视图只能已最小高度进入,只有当滚动视图到达顶部时才扩大到完整高度。
exitUntilCollapsed: 滚动退出屏幕,最后折叠在顶端。
我们上面的布局中 给Toolbar设置了app:layout_scrollFlags属性,因此,Toolbar是可以滚动出屏幕,且向下滚动有可以出现。
为了使得Toolbar可以滑动,我们必须还得有个条件,就是CoordinatorLayout布局下包裹一个可以滑动的布局,比如 RecyclerView,NestedScrollView(经过测试,ListView,ScrollView不支持)具有滑动效果的组件。并且给这些组件设置如下属性来告诉CoordinatorLayout,该组件是带有滑动行为的组件,然后CoordinatorLayout在接受到滑动时会通知AppBarLayout 中可滑动的Toolbar可以滑出屏幕了。
app:layout_behavior="@string/appbar_scrolling_view_behavior"
- CoordinatorLayout结合AppBarLayout
- CoordinatorLayout结合AppBarLayout的基本属性
- recyclerview,AppBarLayout,Toolbar,CoordinatorLayout 的结合使用~
- CoordinatorLayout,AppBarLayout,CollapsingToolbarLayout,Toolbar,NestedScrollView,RecyclerView结合使用
- Android CoordinatorLayout + AppBarLayout
- CoordinatorLayout 之 AppBarLayout
- CollapsingToolbarLayout / AppBarLayout / CoordinatorLayout / FloatingActionB
- AppBarLayout,CoordinatorLayout常用属性
- CoordinatorLayout+AppBarLayout的使用
- 初涉CoordinatorLayout,AppBarLayout,CollapsingToolbarLayout
- CoordinatorLayout,AppBarLayout, NestedScrollView
- CoordinatorLayout + AppBarLayout + ToolBar
- CoordinatorLayout + AppBarLayout+GridView
- CoordinatorLayout&AppBarLayout&CollapsingToolbarLayout组合
- AppBarLayout&CoordinatorLayout&Behavior
- Snackbar、CoordinatorLayout、CardView、AppBarLayout
- CoordinatorLayout+AppBarLayout+appbar_scrolling_view_behavior
- AppBarLayout、CoordinatorLayout、CollapsingToolbarLayout、NestedScrollView
- CENTOS系统安装zookeeper-3.4.8集群
- 如何看懂iOS的Crash报告
- How To Run Spring.io guides
- xcode 调试c++
- luaj——java程序中运行lua
- CoordinatorLayout结合AppBarLayout
- 也谈Spring Bean的生命周期
- iOS录音实践
- 使用Java实现的苹果IAP二次验证主要逻辑过程及原创代码
- 需求管理碎碎念
- java处理Oracle中的clob转换成String
- iOS沙盒机制总结
- iOS知识--Gesture Recognizers与触摸事件分发
- 12个实用的 Javascript 技巧