Android5.0新特性之——按钮点击效果动画(涟漪效果)
Android5.0 Material Design设计的动画效果
RippleDrawable涟漪效果
涟漪效果是Android5.0以后的新特性。为了兼容性,建议新建drawable-v21文件夹来存放RippleDrawable,drawable文件夹下也要放相应的适配图片。(这里可以安装一个AndroidSelector插件,具体的可以参考https://blog.csdn.net/oqihaogongyuan/article/details/53102615的第三部分)
涟漪动画主要是对于ripple标签的使用。,其中ripple节点的,必须要设置color属性。这里根节点的设置的color就是涟漪效果的波纹颜色。子节点的item设置的drawable是涟漪效果的背景(也可以认为是涟漪效果的展示范围)。
我这里根据场景分了4种不同的效果。话不多说先上图。

1、只有ripple节点,无item子节点。通过效果图可以看出,涟漪效果的扩散范围没有限制。已经扩散到了父控件。
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@color/colorBtn">
</ripple>
2、含有一个item节点。通过效果图,可以看到,控件显示了设置的背景色。涟漪效果的范围得到了控制。
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android" android:color="@color/colorBtn">
<!--显示默认的 drawable-->
<item android:drawable="@color/colorWhite" />
</ripple>
3、第二种情况已经符合大多数的场景了。但是随着现在的一些视觉效果的变更,可能存在只要涟漪效果,背景可能是透明色的。设置id为mask的item节点,只起到一个涟漪效果限制作用,并不显示设置的drawable
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android" android:color="@color/colorBtn">
<item
android:id="@android:id/mask"
android:drawable="@color/colorPrimary"/>
</ripple>
4、第四种其实和第二种效果上是一样的。个人感觉没有什么区别。希望了解的大牛进行指点
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android" android:color="@color/colorBtn">
<!--显示默认的 drawable-->
<item android:drawable="@color/colorWhite" />
<item
android:id="@android:id/mask"
android:drawable="@color/colorAccent"/>
</ripple>
我的布局文件:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.gaosiedu.android50.MainActivity"> <Button
android:id="@+id/btn_touch_no"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="48dp"
android:background="@drawable/ripple_item_no"
android:text="无item效果"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> <Button
android:id="@+id/btn_touch_single"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="44dp"
android:background="@drawable/ripple_item_single"
android:text="有item效果"
app:layout_constraintEnd_toEndOf="@+id/btn_touch_no"
app:layout_constraintStart_toStartOf="@+id/btn_touch_no"
app:layout_constraintTop_toBottomOf="@+id/btn_touch_no" /> <Button
android:id="@+id/btn_touch_mask"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:background="@drawable/ripple_item_mask"
android:text="item含mask效果"
app:layout_constraintEnd_toEndOf="@+id/btn_touch_single"
app:layout_constraintStart_toStartOf="@+id/btn_touch_single"
app:layout_constraintTop_toBottomOf="@+id/btn_touch_single" /> <Button
android:id="@+id/btn_touch_double"
android:layout_width="360dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginTop="40dp"
android:background="@drawable/ripple_item_double"
android:text="2个item含mask效果"
app:layout_constraintEnd_toEndOf="@+id/btn_touch_mask"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="@+id/btn_touch_mask"
app:layout_constraintTop_toBottomOf="@+id/btn_touch_mask" /> </android.support.constraint.ConstraintLayout>
Android5.0新特性之——按钮点击效果动画(涟漪效果)的更多相关文章
- Android5.0新特性:RecyclerView实现上拉加载更多
RecyclerView是Android5.0以后推出的新控件,相比于ListView可定制性更大,大有取代ListView之势.下面这篇博客主要来实现RecyclerView的上拉加载更多功能. 基 ...
- Android5.0新特性-Material Design
概述 2014年,Google携Android5.X重装归来.全新的UI设计和更加优化的性能,令开发人员眼前一亮 安装和配置Android5.0开发环境 开发Android还得靠AS.下载地址 htt ...
- Android5.0新特性——兼容性(support)
兼容性 虽然Material Design新增了许多新特性,但是并不是所有新内容对对下保持了兼容. 使用v7包 v7 support libraries r21 及更高版本包含了以下Material ...
- Android5.0新特性——全新的动画(animation)
全新的动画 在Material Design设计中,为用户与app交互反馈他们的动作行为和提供了视觉上的连贯性.Material主题为控件和Activity的过渡提供了一些默认的动画,在android ...
- Kotlin实例----android5.0新特性之palette
一.Palette的使用 使用Palette可以让我们从一张图片中拾取颜色,将拾取到的颜色赋予ActionBar,StatusBar以及UI背景色可以让界面色调实现统一或者加载不同图片时同步变化色调 ...
- Android5.0新特性——新增的Widget(Widget)
新增的Widget RecyclerView RecyclerView是ListView的升级版,它具备了更好的性能,且更容易使用.和ListView一样,RecyclerView是用来显示大量数据的 ...
- Android5.0新特性——阴影和剪裁(shadow)
阴影和剪裁 View的z属性 Material Design建议为了凸显布局的层次,建议使用阴影效果,并且Android L为了简化大家的工作,对View进行了扩展,能使大家非常方便的创建阴影效果: ...
- Android5.0新特性——图片和颜色(drawable)
图片和颜色 tint属性 tint属性一个颜色值,可以对图片做颜色渲染,我们可以给view的背景设置tint色值,给ImageView的图片设置tint色值,也可以给任意Drawable或者NineP ...
- Android5.0新特性——Material Design简介
Material Design Material Design简介 Material Design是谷歌新的设计语言,谷歌希望寄由此来统一各种平台上的用户体验,Material Design的特点是干 ...
随机推荐
- [strongswan] strongswan是如何实现与xfrm之间的trap机制的
目录 strongswan与xfrm之间的trap机制 0. 1. 前言 2. 描述 2.1 none 2.2 trap 3. 实验与过程 3.1 trap实验 3.2 none实验 4 背景知识 5 ...
- 工作中对git使用的总结
git与svn的区别,简单的说, svn在checkout后,如果不提交,那么版本库没有记录,如果修改的文件比较多,中间想回退几个文件,非常麻烦.git 是clone下来代码和记录,不提交 ...
- [Android]使用Spring for Android改善数据交互流程
如果开发一个和服务端有数据交互android应用,流程通常是这样的:界面收集用户数据之后,将它转换成JSON或者XML格式的字符串,以HTTP的方式提交给服务端,获得返回的文本数据,再将数据解析为ja ...
- libcurl.a 跨平台
编译成libxxx.a文件后, 通过lipo把多个不同架构的文件合并起来成为一个文件 在build setting 设置 head search path , library search path ...
- Python多线程下存在_strptime的问题
由于Python的datetime和time中的_strptime方法不支持多线程,运行时会报错:AttributeError: _strptime code: # -*- coding:utf-8 ...
- nuxt 2
原文出处:
- vue中使用vue-quill-editor及上传图片到自己服务器
第一步,下载依赖 cnpm install vue-quill-editor --save 第二步,再main.js里引入组件(我这里是全局注册) // 富文本编辑器 import VueQuillE ...
- 我的第三篇博客(激动激动真激动!!!)A-B Problem
#210. 差(A-B problem) 题目描述 楠楠在网上刷题,感觉第一题:求两数的和(A+B Problem)太无聊了,于是增加了一题:A-B Problem,难倒了一群小朋友,哈哈. 题目是这 ...
- 《linux就该这么学》第十四节课:第13章,部署DNS域名解析服务(bind服务)
(借鉴请改动) 第十二章收尾 12.2.nfs网络文件系统 RHEL7默认安装了nfs,配置文件在 /etc/export 写入格式:共享目录 允许的客户端(参数) ro ...
- c# 中HttpClient访问Https网站
c# 中HttpClient访问Https网站,加入如下代码: handler = new HttpClientHandler() ;handler.AllowAutoRedirect = true; ...