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新特性之——按钮点击效果动画(涟漪效果)的更多相关文章

  1. Android5.0新特性:RecyclerView实现上拉加载更多

    RecyclerView是Android5.0以后推出的新控件,相比于ListView可定制性更大,大有取代ListView之势.下面这篇博客主要来实现RecyclerView的上拉加载更多功能. 基 ...

  2. Android5.0新特性-Material Design

    概述 2014年,Google携Android5.X重装归来.全新的UI设计和更加优化的性能,令开发人员眼前一亮 安装和配置Android5.0开发环境 开发Android还得靠AS.下载地址 htt ...

  3. Android5.0新特性——兼容性(support)

    兼容性 虽然Material Design新增了许多新特性,但是并不是所有新内容对对下保持了兼容. 使用v7包 v7 support libraries r21 及更高版本包含了以下Material ...

  4. Android5.0新特性——全新的动画(animation)

    全新的动画 在Material Design设计中,为用户与app交互反馈他们的动作行为和提供了视觉上的连贯性.Material主题为控件和Activity的过渡提供了一些默认的动画,在android ...

  5. Kotlin实例----android5.0新特性之palette

    一.Palette的使用 使用Palette可以让我们从一张图片中拾取颜色,将拾取到的颜色赋予ActionBar,StatusBar以及UI背景色可以让界面色调实现统一或者加载不同图片时同步变化色调 ...

  6. Android5.0新特性——新增的Widget(Widget)

    新增的Widget RecyclerView RecyclerView是ListView的升级版,它具备了更好的性能,且更容易使用.和ListView一样,RecyclerView是用来显示大量数据的 ...

  7. Android5.0新特性——阴影和剪裁(shadow)

    阴影和剪裁 View的z属性 Material Design建议为了凸显布局的层次,建议使用阴影效果,并且Android L为了简化大家的工作,对View进行了扩展,能使大家非常方便的创建阴影效果: ...

  8. Android5.0新特性——图片和颜色(drawable)

    图片和颜色 tint属性 tint属性一个颜色值,可以对图片做颜色渲染,我们可以给view的背景设置tint色值,给ImageView的图片设置tint色值,也可以给任意Drawable或者NineP ...

  9. Android5.0新特性——Material Design简介

    Material Design Material Design简介 Material Design是谷歌新的设计语言,谷歌希望寄由此来统一各种平台上的用户体验,Material Design的特点是干 ...

随机推荐

  1. Apache Arrow

    https://www.kdnuggets.com/2017/02/apache-arrow-parquet-columnar-data.html https://arrow.apache.org/ ...

  2. kubernetes in action - Services

    问题,如何将Pod所提供的功能提供给别人用?微服务,是服务,所以关键要把服务提供出去 直接把pod的静态ip提供给用户用,这个会有很多问题,比如failover,扩容,负载均衡等 所以需要servic ...

  3. 安卓demo

    https://github.com/Blankj/AndroidUtilCode/blob/master/utilcode/README-CN.md

  4. windows red5相关

    red5部署 前段时间把red5服务器搭建好了,现在记录下是如何搭建的.1,下载对应版本的red5https://github.com/Red5/red5-server/releases2,如果没有安 ...

  5. 如何查看正在执行sql的语句及其父语句调用?如何查看正在执行SQL的具体参数值与执行计划?

    ---SQL Server查询正在执行的SQL语句及执行计划 select ds.session_id,dr.start_time,db_name(dr.database_id),dr.blockin ...

  6. [jquery.validate]自定义方法实现"手机号码或者固定电话"的逻辑验证

    最近项目开发中遇到这样的需求“手机号码或者固话至少填写一个”,如下图所示: 项目采用的jquery.validate.js验证组件,目前组件不支持这种“或”逻辑的验证,于是就自己定义一个 jQuery ...

  7. html-webpack-plugin插件使用

    项目使用hightopo框架,使用webpack打包.这里的场景是:点击预览按钮,页面会打开一个新页面. 但是由于使用了webpack打包,所以直接使用以下代码是不行的.报404 window.ope ...

  8. Linux下利用文件描述符恢复的成功失败实验

    1.测试环境准备[oracle@redhat3 ~]$ uname -aLinux redhat3 2.6.32-573.el6.x86_64 #1 SMP Wed Jul 1 18:23:37 ED ...

  9. 使用datagrid时json的格式

    EasyUI的DataGrid要求返回的JSON数据集是这样的形式: {"total":总记录数量,"rows":[数据记录数组]}. 例如: {"t ...

  10. 与图论的邂逅03:Lengauer-Tarjan

    回想一下,当我们在肝无向图连通性时,我们会遇到一个神奇的点——它叫割点.假设现在有一个无向图,它有一个割点,也就是说把割点删了之后图会分成两个联通块A,B.设点u∈A,v∈B,在原图中他们能够互相到达 ...