Material Design 的一些UI 平常开发还是用的比较多的,以前没写,最近总结一下,写一篇博客,要求版本在5.0以上。

主要介绍了FloatActionButton,CoordinatorLayout,CollapsingToolbarLayout,AppBarLayout,Toolbar,TabLayout,RecyclerView,CardView

案例中包含了这些的使用;

使用前在build.gradle 添加

    compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.jaeger.statusbaruitl:library:1.1.1'
compile 'com.android.support:design:24.2.+'
compile 'com.android.support:cardview-v7:24.2.1'

1:FloatActionButton(悬浮按钮

FloatActionButton是ImageButton的继承类,其用法跟普通的Button基本类似,悬浮的效果,故其使用的重点其实是在布局上。

效果如图:

         

 <android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:layout_gravity="bottom|right"
app:fabSize="normal"
app:elevation="6dp"
android:src="@mipmap/ic_launcher"
app:pressedTranslationZ="25dp"
/>

结合Snackbar使用

属性介绍:

1、app:borderWidth=""------------------边框宽度,通常设置为0 ,用于解决Android 5.X设备上阴影无法正常显示的问题

2、app:backgroundTint=""---------------按钮的背景颜色,不设置,默认使用theme中colorAccent的颜色

3、app:rippleColor=""--------------------点击的边缘阴影颜色

4、app:elevation=""----------------------边缘阴影的宽度

5、app:pressedTranslationZ="16dp"-----点击按钮时,按钮边缘阴影的宽度,通常设置比elevation的数值大

2:CoordinatorLayout+AppBarLayout+CollapsingToolbarLayout(工具栏伸缩折叠)

实现Material Design里折叠工具栏,它继承至FrameLayout,给它设置layout_scrollFlags,

它可以控制包含在CollapsingToolbarLayout中的控件(如:ImageView、Toolbar)在响应layout_behavior事件时作出相应的scrollFlags滚动事件(移除屏幕或固定在屏幕顶端)。

效果如图:

    

实现效果图的代码:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"> <android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="226dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:fitsSystemWindows="true"> <android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginStart="48dp"
app:expandedTitleMarginEnd="64dp"> <ImageView
app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed"
android:id="@+id/backdrop"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:fitsSystemWindows="true"
android:src="@mipmap/zhangwo_hometop1"
app:layout_collapseMode="parallax"
/>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:layout_collapseMode="pin" /> </android.support.design.widget.CollapsingToolbarLayout> </android.support.design.widget.AppBarLayout> <android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="none" /> </android.support.v4.widget.NestedScrollView> <android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
app:layout_anchor="@id/appbar"
app:layout_anchorGravity="bottom|right|end"
android:src="@mipmap/ic_launcher"
android:layout_margin="15dp"
android:clickable="true"/> </android.support.design.widget.CoordinatorLayout>

3:CoordinatorLayout+AppBarLayout+TabLayout(工具栏伸缩折叠)

CoordinatorLayout是support.design包中的控件,它可以说是Design库中最重要的控件,

CoordinatorLayout 实现了多种Material Design中提到的滚动效果。

效果图:

  

效果图布局

<?xml version="1.0" encoding="utf-8"?>
<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:orientation="vertical"> <android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> <!--app:layout_scrollFlags
1、scroll: 所有想滚动出屏幕的view都需要设置这个flag,
没有设置这个flag的view将被固定在屏幕顶部。
例如,TabLayout 没有设置这个值,将会停留在屏幕顶部。
2、enterAlways: 设置这个flag时,向下的滚动都会导致该view变为可见,启用快速“返回模式”。
3、enterAlwaysCollapsed: 当你的视图已经设置minHeight属性又使用此标志时,
你的视图只能已最小高度进入,只有当滚动视图到达顶部时才扩大到完整高度。
4、exitUntilCollapsed: 滚动退出屏幕,最后折叠在顶端。--> <android.support.v7.widget.Toolbar
android:id="@+id/appbar_toolbar"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/Theme.AppCompat.Light"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary" /> <android.support.design.widget.TabLayout
android:id="@+id/tabs"
app:tabGravity="fill"
app:tabMode="fixed"
android:layout_width="match_parent"
android:layout_height="wrap_content" /> </android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<!--三:滑动组件的动画,满一屏才有效果。
app:layout_behavior=”@string/appbar_scrolling_view_behavior”
--> </android.support.design.widget.CoordinatorLayout>

其他相关请看博客:

Android之ToolBar和自定义ToolBar实现沉浸式状态栏

Android之新闻客服端顶部导航栏Tab点击和左右滑动实现切换界面

Android之侧滑菜单DrawerLayout的使用

Android之SwipeRefreshLayout下拉刷新组件

Android之 RecyclerView,CardView 详解和相对应的上拉刷新下拉加载

由于代码太多,就不一一贴出来了,源码直接下载即可

源码下载

Android----Material Design之(FloatActionButton,CoordinatorLayout,CollapsingToolbarLayout,AppBarLayout,TabLayout等)的更多相关文章

  1. 【转】Material Design 折叠效果 Toolbar CollapsingToolbarLayout AppBarLayout

    我非常喜欢Material Design里折叠工具栏的效果,bilibili Android客户端视频详情页就是采用的这种设计.这篇文章的第二部分我们就通过简单的模仿bilibili视频详情页的实现来 ...

  2. Android Material Design的FloatingActionButton,Snackbar和CoordinatorLayout

    如果是为了兼容低版本的Android系统,则需要引用Android Material Design的扩展支持库,我在之前的一篇文章张,较为详细的说明了如何导入Android Material Desi ...

  3. Android Material Design 兼容库的使用

    Android Material Design 兼容库的使用 mecury 前言:近来学习了Android Material Design 兼容库,为了把这个弄懂,才有了这篇博客,这里先推荐两篇博客: ...

  4. Android Material Design Ripple Effect在Android5.0(SDK=21)以下Android版本崩溃问题解决

    Android Material Design Ripple Effect在Android5.0(SDK=21)以下Android版本崩溃问题解决 附录1的Android Ripple Effect水 ...

  5. Android Material Design : Ripple Effect水波波纹荡漾的视觉交互设计

     Android Material Design : Ripple Effect水波波纹荡漾的视觉交互设计 Android Ripple Effect波纹荡漾效果,是Android Materia ...

  6. MaterialEditText——Android Material Design EditText控件

    MaterialEditText是Android Material Design EditText控件.可以定制浮动标签.主要颜色.默认的错误颜色等. 随着 Material Design 的到来, ...

  7. Android Material Design控件学习(三)——使用TextInputLayout实现酷市场登录效果

    前言 前两次,我们学习了 Android Material Design控件学习(一)--TabLayout的用法 Android Material Design控件学习(二)--Navigation ...

  8. Android material design support library -- CollapsingToolbarLayout简介

    本文是codetrick上material design support library教程的第三篇,主要讲的是CollapsingToolbarLayout的概念和应用方法. 原文链接:Materi ...

  9. Android Material Design之CollapsingToolbarLayout使用

    CollapsingToolbarLayout作用是提供了一个可以折叠的Toolbar,它继承至FrameLayout,给它设置layout_scrollFlags,它可以控制包含在Collapsin ...

  10. Android Material Design:基于CoordinatorLayout实现向上滚动导航条ToolBar滚出、向下滚动导航条滚出

    activity_main.xml: <android.support.design.widget.CoordinatorLayout xmlns:android="http://sc ...

随机推荐

  1. php实现异步的程序调用

    浏览器和服务器之间的通信是基于HTTP协议进行链接通讯的,它是一种请求和相应的协议.浏览器通过URL向服务器发送请求,服务器接收到请求并执行请求,然后服务器将执行完成的数据返回到客户端. 这就存在一个 ...

  2. R语言之多重共线性的判别以及解决方法

    多重共线性(Multicollinearity)是指线性回归模型中的解释变量之间由于存在精确相关关系或高度相关关系而使模型估计失真或难以估计准确.   1.可以计算X矩阵的秩qr(X)$rank,如果 ...

  3. 关于websocket通讯

    var ws = { init:function(callback){ var _this = this; _this.callback = callback; }, websocket:functi ...

  4. CSS 换行知多少: word-wrap && word-break && white-space && word-spacing

    word-wrap : 首先提一下,word-wrap 这个 CSS 属性在CSS3中已经被更名为 overflow-wrap,这样语义化也是为了避免与 word-break 混淆: Referenc ...

  5. 如何将python3.6软件的py文件打包成exe程序

    在我们完成一个Python项目或一个程序时,希望将Python的py文件打包成在Windows系统下直接可以运行的exe程序.在浏览网上的资料来看,有利用pyinstaller和cx_Freeze进行 ...

  6. ACM-ICPC 2018 焦作赛区网络预赛 F. Modular Production Line (区间K覆盖-最小费用流)

    很明显的区间K覆盖模型,用费用流求解.只是这题N可达1e5,需要将点离散化. 建模方式步骤: 1.对权值为w的区间[u,v],加边id(u)->id(v+1),容量为1,费用为-w; 2.对所有 ...

  7. C#打印类

    using System;using System.Collections.Generic;using System.Text;using System.Windows.Forms;using Sys ...

  8. $一步一步学Matlab(4)——使用Matlab进行初等数学运算

    Matlab可以看成是一个功能强大的计算器,那么既然是计算器,进行基本的数学运算绝对是必不可少的.本文主要讲解如何用Matlab做初等数学运算,所谓"初等数学运算",可以理解成是小 ...

  9. Js答辩总结

    JS项目总结   在做完项目后,我又学到了很多知识,有些知识在书中或许都学不到,这就是动手实践的效果与好处. 这次项目能做完,可以说不是我一个人的正真成果,因为JS是一门较难的课,做项目时往往会遇到很 ...

  10. GRUB2 分析 (一)

    GRUB是目前较流行启动引导程序.其第二版被主流Linux发行版所包括.本文将探索和分析GRUB的设计和实现机制. boot.S是第一个研究对象,因为boot.S将被编译成boot.img(512字节 ...