Android material design support library -- CollapsingToolbarLayout简介
本文是codetrick上material design support library教程的第三篇,主要讲的是CollapsingToolbarLayout的概念和应用方法。
原文链接:Material Design Support Library Tutorial – Part 3
Collapsing Toolbar Layout
想实现工具栏collpasing的效果,需要将工具栏(Toolbar)包裹在CollapsingToolbarLayout内。布局的结构如下:
<android.support.design.widget.CoordinatorLayout >
<android.support.design.widget.AppBarLayout >
<android.support.design.widget.CollapsingToolbarLayout >
<ImageView />
<android.support.v7.widget.Toolbar />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<!-- Your scrollable content here -->
</android.support.design.widget.CoordinatorLayout>
CoordinatorLayout
CoordinatorLayout是一个加强的FrameLayout,指定了子视图的多种交互行为。允许浮动的视图锚定在布局中。
AppBarLayout
AppBarLayout是一个垂直的线性布局,实现了material design中关于app bar概念的多个特性,也就是滚动手势。
子视图应该通过setScrollFlags(int)
方法给出它们想要的滚动行为,相关联的布局xml属性是app:layout_scrollFlags
。
这个控件重度依赖CoordinatorLayout,而且需要是CoordinatorLayout的直接子控件。如果你把AppBarLayout放在别的ViewGroup中,它的大多数功能都将失效。
CollapsingToolbarLayout
CollapsingToolbarLayout是对Toolbar的包装,实现了一个可以收缩的应用栏。它被设计成作为AppBarLayout的直接子视图来使用。它包含以下的特性:
Collapsing title
这个标题在布局完全可见时最大,当布局滚出屏幕时会收缩变小。你可以通过setTitle(CharSequence)
方法来设置标题。标题文本的外观可以通过collapsedTextAppearance
和expandedTextAppearance
属性来修改。
Content scrim
一个full-bleed(满血?)的scrim(帘布?),当滚动位置到达一定阈值时会显示或者隐藏。你可以通过setContentScrim(Drawable)
方法来改变它。
Status bar scrim
这也是一个scrim(帘布?),当滚动位置到达一定的阈值时会显示或隐藏在状态栏(status bar)后面。你可以通过setStatusBarScrim(Drawable)
方法来改变它。在LOLLIPOP设备上,只有设置了fit system windows属性,它才有效。
Parallax scrolling children
在这个布局中,子视图可以选择视差滚动。参见COLLAPSE_MODE_PARALLAX
和setParallaxMultiplier(float)
。
Pinned position children
子视图也可选择在全局空间中固定位置。在实现收缩效果时这很有用,因为即使布局在移动,它上面的Toolbar也可以固定在一个位置。
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<com.codentrick.materialdesigndemo.SquareImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax" />
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.CollapsingToolbarLayout>
java代码:
CollapsingToolbarLayout collapsingToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);
collapsingToolbarLayout.setTitle("This is title");
collapsingToolbarLayout.setExpandedTitleColor(getResources().getColor(android.R.color.transparent));
相关代码和效果参见原作者的github库MaterialDesignSupportSample。
Android material design support library -- CollapsingToolbarLayout简介的更多相关文章
- Android Meterial Design Support Library
extends:http://inthecheesefactory.com/blog/android-design-support-library-codelab At the moment I be ...
- Android应用Design Support Library完全使用实例
阅读目录 2-1 综述 2-2 TextInputLayout控件 2-3 FloatingActionButton控件 2-4 Snackbar控件 2-5 TabLayout控件 2-6 Navi ...
- 安卓高级3 Android应用Design Support Library完全使用实例
原作者:http://www.open-open.com/lib/view/open1433385856119.html 1 背景 上周一年一度的Google IO全球开发者大会刚刚结束,Google ...
- 如何使用android design support library
Android应用Design Support Library完全使用实例 - OPEN 开发经验库http://www.open-open.com/lib/view/open143338585611 ...
- Android Material Design 兼容库的使用
Android Material Design 兼容库的使用 mecury 前言:近来学习了Android Material Design 兼容库,为了把这个弄懂,才有了这篇博客,这里先推荐两篇博客: ...
- Material Design 开发利器:Android Design Support Library 介绍
转自:https://blog.leancloud.cn/3306/ Android 5.0 Lollipop 是迄今为止最重大的一次发布,很大程度上是因为 material design —— 这是 ...
- Material Design with the Android Design Support Library
Material Design with the Android Design Support Library 原文http://www.sitepoint.com/material-design-a ...
- Android Design Support Library使用详解
Android Design Support Library使用详解 Google在2015的IO大会上,给我们带来了更加详细的Material Design设计规范,同时,也给我们带来了全新的And ...
- Android开发学习之路-Android Design Support Library使用(CoordinatorLayout的使用)
效果图: 上面的这个图有两个效果是,一个是顶部的图片,在上滑之后会隐藏起来并且显示出一个ToolBar(ToolBar类似于ActionBar,但是只有ToolBar是兼容Material Desig ...
随机推荐
- css样式-ime-mode text-transform
今天遇到一个新的css样式: ime-mode text-transform 有效小作用 取值:auto : 默认值.不影响ime的状态.与不指定 ime-mode 属性时相同 active : ...
- Oracle数据库之PL/SQL程序设计简介
PL/SQL程序设计简介 一.什么是PL/SQL? PL/SQL是 Procedure Language & Structured Query Language 的缩写. ORACLE的SQL ...
- PHP微信红包的算法实现探讨
header("Content-Type: text/html;charset=utf-8");//输出不乱码,你懂的 $total=10;//红包总额 $num=8;// 分成8 ...
- Java学习笔记--堆、栈、常量池
参考资料:http://blog.csdn.net/miraclestar/article/details/6039743 Java内存区域模型主要分为4部分 1.方法区 2.本地方法栈 3.栈 4. ...
- 从汇编来看c语言之指针
一.基础研究 将下面的程序编译连接,用debug加载: 首先执行第一条语句: 发现p=(unsigned char *)0x1000;在这里是把1000赋给一个偏移地址为01af.大小为两字节的内存空 ...
- Powershell错误处理,try catch finally
脚本的调试向来是一个艰巨的任务,在powershell出现以前简直是一场灾难.在powershell中微软终于做出了诸多改进,不但有了$Error.-whatif,也有了ISE.而在语法上也增加了tr ...
- 实现QQslidingMenu侧滑效果学习笔记
声明:只是自己的学习笔记,所以,只作为博友的参考,不喜勿喷 实现思路: 自定义继承HorizontalScrollView的控件 项目github地址: https://github.com/ysno ...
- redis 异常排查
异常排查 redis-server redis.windows.conf D:\redis-2.8.17>redis-server.exe redis.windows.conf[4692] 27 ...
- hadoop2.2.0的WordCount程序
package com.my.hadoop.mapreduce.wordcount; import java.io.IOException; import org.apache.hadoop.conf ...
- JS-Array数组内置对象
直接上代码: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <ti ...