Android控件大全(四)——CoordinatorLayout
CoordinatorLayout 其实就是个高级的FrameLayout,用于协调子布局
要使用该控件,需要再gradle中加入:
compile 'com.android.support:design:24.2.1'
1、CoordinatorLayout与AppBarLayout
<android.support.design.widget.CoordinatorLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
app:layout_scrollFlags="scroll"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize">
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:id="@+id/recycler"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v7.widget.RecyclerView>
</android.support.design.widget.CoordinatorLayout>
注意:代码的第10行和第16行 @string/appbar_scrolling_view_behavior 是系统自带的一个Behavior,我们之后再讨论,这边先看一下 app:layout_scrollFlags="scroll"
scroll、enterAlways、enterAlwaysCollapsed、exitUtilCollapsed、snap 五中可选
scroll:伴随着滚动时间滚进滚出屏幕,如果设置了其他的flag,这个flag是必须写上的,不然没有效果;前面所有的子View都必须带上这个属性,不然没有效果
enterAlways:快速返回模式,优先滚动toolbar
enterAlwaysCollapsed :要使用这种属性,必须设置一个minHeight,先将toolbar滚动至minHeight,然后滚动RecycylerView,滚动至顶部之后就继续滚动toolbar,并且需要配合enterAlways一起使用,否则没有效果
exitUtilCollapsed:先将toolbar滚动至minHeight,然后滚动recyclerView,toolbar不会完全滚出屏幕
snap:toolbar滚动添加一个吸附的效果
2、CoordinatorLayout与CollapsingToolbarLayout
<android.support.design.widget.CoordinatorLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="256dp">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapse"
app:contentScrim="#30469b"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
app:layout_collapseMode="parallax"
android:scaleType="center"
android:src="@mipmap/timg"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.v7.widget.Toolbar
app:layout_collapseMode="pin"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize">
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:id="@+id/recycler"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v7.widget.RecyclerView> </android.support.design.widget.CoordinatorLayout>
注意:第11行:app:contentScrim设置折叠之后的颜色;
第12行,flag必须设置成 scroll|exitUntilCollapsed;
第16行 app:layout_collapseMode 设置成 parallax,表示图片会随着滚动开始渐变;
第22行:设置成pin表示toolbar会停留在最上方
此时如果要设置文字必须从CollapsingToolbarLayout入手
<android.support.design.widget.FloatingActionButton
app:layout_anchor="@id/appbar"
app:layout_anchorGravity="right|bottom|end"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
实现floatingActionButton与AppbarLayout一同消失和呈现
Android控件大全(四)——CoordinatorLayout的更多相关文章
- Android控件大全(二)——Toolbar
1.隐藏Actionbar 代码中设置:requestWindowFeature(Window.FEATURE_NO_TITLE) //如果Activity是继承自AppCompatActiv ...
- Android控件大全(三)——RecyclerView
是时候用RecyclerView来替换ListView和GridView了 好处就不多说了,百度一搜一大把,来介绍下用法 先定义个适配器: public class BottomSheetAdapte ...
- Android控件大全(一)——DialogFragment创建对话框
DialogFragment在android 3.0时被引入.是一种特殊的Fragment,用于在Activity的内容之上展示一个模态的对话框.典型的用于:展示警告框,输入框,确认框等等. 在Dia ...
- Android控件Gridview实现仿支付宝首页,Fragment底部按钮切换和登录圆形头像
此案例主要讲的是Android控件Gridview(九宫格)完美实现仿支付宝首页,包含添加和删除功能:Fragment底部按钮切换的效果,包含四个模块,登录页面圆形头像等,一个小项目的初始布局. 效果 ...
- Android群英传笔记——第三章:Android控件架构与自定义控件讲解
Android群英传笔记--第三章:Android控件架构与自定义控件讲解 真的很久没有更新博客了,三四天了吧,搬家干嘛的,心累,事件又很紧,抽时间把第三章大致的看完了,当然,我还是有一点View的基 ...
- SNF开发平台WinForm-Grid表格控件大全
我们在开发系统时,会有很多种控件进行展示,甚至有一些为了方便的一些特殊需求. 那么下面就介绍一些我们在表格控件里常用的方便的控件: 1.Grid表格查询条 Grid表格下拉 3.Grid表格弹框选 ...
- Android控件Gridview实现多个menu模块,可添加可删除
此案例主要讲的是Android控件Gridview(九宫格)完美实现仿支付宝首页,包含添加和删除功能:Fragment底部按钮切换的效果,包含四个模块,登录页面圆形头像等,一个小项目的初始布局. 效果 ...
- Delphi 控件大全
delphi 控件大全(确实很全) delphi 控件查询:http://www.torry.net/ http://www.jrsoftware.org Tb97 最有名的工具条(ToolBar ...
- [Android Pro] android控件ListView顶部或者底部也显示分割线
reference to : http://blog.csdn.net/lovexieyuan520/article/details/50846569 在默认的Android控件ListView在 ...
随机推荐
- 利用背景流量数据(contexual flow data) 识别TLS加密恶意流量
识别出加密流量中潜藏的安全威胁具有很大挑战,现已存在一些检测方法利用数据流的元数据来进行检测,包括包长度和到达间隔时间等.来自思科的研究人员扩展现有的检测方法提出一种新的思路(称之为“dataomni ...
- 【Todo】已经打开的页面需要清掉的坑
下面是当前我浏览器里面打开的技术文章.需要清掉.一个坑一个坑地填吧. 微信文件传输里面也有几篇12.6号的<Akuna Capital电面面经><2016最流行的Java EE服务器 ...
- Linux Shell高级技巧
Linux Shell高级技巧(一) http://www.cnblogs.com/stephen-liu74/archive/2011/12/22/2271167.html一.将输入信息转换为大写字 ...
- SSH login without password
SSH login without password Your aim You want to use Linux and OpenSSH to automize your tasks. Theref ...
- linux的主分区与逻辑分区的关系
主分区和扩展分区的差别在于主分区位于硬盘的最開始.MBR 扇区的位置.这个位置的数据在计算机启动时.会自己主动被 BIOS 读取而且运行,也就是说这个位置的分区表会自己主动被 BIOS 读取到内 ...
- 如何干掉那些.ipch 与 .sdf文件
参考资料: http://blog.163.com/yangjun1988422@126/blog/static/47412917201074446054/ vs2010中臃肿的ipch和sd ...
- Development of Intel chipsets interconnection
http://en.wikipedia.org/wiki/Chipset Chipset From Wikipedia, the free encyclopedia A chipset is ...
- bzoj 1030: [JSOI2007]文本生成器 (ac自己主动机上的dp)
1030: [JSOI2007]文本生成器 Time Limit: 1 Sec Memory Limit: 162 MB Submit: 2635 Solved: 1090 [id=1030&qu ...
- 【前端JS】radio 可单选可点击取消选中
普通情况下 radio 单选框仅仅能实现多选一的效果,可是一旦选择当中一个后,这个单选框就不可点击取消其选中状态了.这样的功能在某些业务环境下并不适用.有时我们既须要单选框的多选一效果.也须要复选框的 ...
- POJ--2284--That Nice Euler Circuit【平面图欧拉公式】
链接:id=2284">http://poj.org/problem?id=2284 题意:一个自己主动绘图的机器在纸上(无限大)绘图,笔尖从不离开纸,有n个指令,每一个指令是一个坐标 ...