代码:

import android.animation.ValueAnimator;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;
import android.view.animation.LinearInterpolator; import net.wt.gate.dev.libs.log.L; import java.util.concurrent.CopyOnWriteArrayList; public class DoorBellAnimal extends View {
private int centerX;
private int centerY;
private int startRadius = 10;
private int endRadius = 250;
private int startAlpha = 250; private CopyOnWriteArrayList<RippleCircle> rippleCircles = new CopyOnWriteArrayList<>(); public DoorBellAnimal(Context context) {
this(context, null);
} public DoorBellAnimal(Context context, @Nullable AttributeSet attrs) {
this(context, attrs, 0);
} public DoorBellAnimal(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr); } @Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int width = MeasureSpec.getSize(widthMeasureSpec);
int height = MeasureSpec.getSize(heightMeasureSpec); centerX = width / 2;
centerY = height / 2;
setMeasuredDimension(widthMeasureSpec, heightMeasureSpec);
} @Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas); for (RippleCircle circle : rippleCircles) {
circle.draw(canvas);
} } @Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
startRipple();
startAnimal(); } private void startRipple() {
postOnAnimationDelayed(() -> { RippleCircle rippleCircle = new RippleCircle();
rippleCircles.add(rippleCircle);
startRipple();
}, 500); } private ValueAnimator valueAnimator; @Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
valueAnimator.cancel();
valueAnimator.end();
} private void startAnimal() {
valueAnimator = ValueAnimator.ofInt(0, 60);
valueAnimator.setInterpolator(new LinearInterpolator());
valueAnimator.setDuration(3000);
valueAnimator.setRepeatCount(ValueAnimator.INFINITE);
valueAnimator.setRepeatMode(ValueAnimator.RESTART); valueAnimator.addUpdateListener(animation -> postInvalidateOnAnimation());
valueAnimator.start(); } /**
* 需要画的 圆圈,需要不断改变半径何透明度
*/
private class RippleCircle { private Paint paint; //画笔
private int progress; //当前进度 private int perRadius = (endRadius - startRadius) / 60;
private int perAlpha = startAlpha / 60; RippleCircle() {
paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setColor(Color.WHITE);
progress = 0;
} void draw(Canvas canvas) { if (paint == null) {
return;
}
if (progress >= 60) {
rippleCircles.remove(this);
return;
}
progress++;
float currentAlpha = startAlpha - perAlpha * progress;
paint.setAlpha((int) (currentAlpha)); //更改透明度
float current = startRadius + perRadius * progress;
canvas.drawCircle(centerX, centerY, current, paint);
}
} }

 

Android开发 自定义View_白色圆型涟漪动画View的更多相关文章

  1. Android开发自定义View

    Android中View组件的作用类似于Swing变成中的JPanel,它只是一个空白的矩形区域,View组件中没有任何内容.对于Android应用的其他UI组件来说,它们都继承了View组件,然后在 ...

  2. android 开发-自定义多节点进度条显示

    看效果图: 里面的线段颜色和节点图标都是可以自定义的. main.xml <RelativeLayout xmlns:android="http://schemas.android.c ...

  3. [android 开发篇] 易白教程网址

    http://www.yiibai.com/android/android_bluetooth.html

  4. android开发 自定义图文混排控件

    功能:图文混排,可自动缩放字体,如图: 单点触控使用的代码来自:http://blog.csdn.net/xiaanming/article/details/42833893  谢谢博主! 在该dem ...

  5. Android开发之仿微信显示更多文字的View

    最近开发需求中要模仿微信朋友圈文章的展开收起功能,网上找了找,发现都有问题,于是乎自己在前辈的基础上进行了一定量的修改,下边将源码贴出来供大家参考:1.主Activity布局文件就不粘贴了,很简单,就 ...

  6. Android开发 - 掌握ConstraintLayout(十一)复杂动画!如此简单!

    介绍 本系列我们已经介绍了ConstraintLayout的基本用法.学习到这里,相信你已经熟悉ConstraintLayout的基本使用了,如果你对它的用法还不了解,建议您先阅读我之前的文章. 使用 ...

  7. Android开发UI之给ListView设置布局动画效果

    1.通过JAVA代码添加,资源文件基本上不修改 XML文件,只添加了一个ListView,就不贴XML文件的代码了. java代码: public class MainActivity extends ...

  8. Android开发之自定义组件和接口回调

    说到自定义控件不得不提的就是接口回调,在Android开发中接口回调用的还是蛮多的.在这篇博客开始的时候呢,我想聊一下iOS的自定义控件.在iOS中自定义控件的思路是继承自UIView, 在UIVie ...

  9. 在Eclipse下搭建Android开发环境教程

    我们昨天向各位介绍了<在NetBeans上搭建Android SDK环境>,前不久也介绍过<在MyEclipse 8.6上搭建Android开发环境>, 都受到了读者的欢迎.但 ...

随机推荐

  1. Jackson第一个程序

    再进入学习jackson库的细节之前,让我们来看看应用程序操作功能.在这个例子中,我们创建一个Student类.将创建一个JSON字符串学生的详细信息,并将其反序列化到学生的对象,然后将其序列化到JS ...

  2. 1-Navicat无法远程连接Ubuntu上的MySQL(已解决)

    转发自: https://jingyan.baidu.com/article/4d58d54156ff069dd4e9c085.html

  3. creat-react-app搭建的项目中按需引入antd以及配置Less和如何修改antd的主题色

    在creat-react-app搭建的项目环境中按需引入antd以及配置less,首先需要暴露出来webpack文件.(此操作不可逆). create-react-app myapp 创建同一个rea ...

  4. 快速读取 C++

    int read() { ; ; char ch=getchar(); ') { if (ch=='-') f=-; ch=getchar(); } ') { x=x*+ch-'; ch=getcha ...

  5. SQL登录报错

    在安装完SQL后,发现报出了error40和53的错误,作为小白的我也是一脸懵逼,明明一切都是按照默认加下一步安装的,为什么到了连接数据库的时候就出现了问题呢? 后来经过调查,发现需要将sql配置管理 ...

  6. 论文学习——《Good View Hunting: Learning Photo Composition from Dense View Pairs》

    论文链接:http://www.zijunwei.org/papers/cvpr18-photo-composition.pdf 代码及数据集链接:https://www3.cs.stonybrook ...

  7. Linux批量解压缩脚本

    #!/bin/bash # 批量解压缩脚本 # 作者: shaohsiung # 时间: // # Store all file names in the tmp directory with the ...

  8. Android SDK Download

    { https://www.androiddevtools.cn/ }

  9. 【latex】latex基础

    文档边距.间距调整 边距调整 \usepackage{geometry} %设置页边距的宏包 \geometry{left=3.0cm,right=2.5cm,top=2.5cm,bottom=2.5 ...

  10. Rootkit之SSDT hook(通过CR0)

    CR0当中有一个写保护位,是保护内存不可写属性的,为了能够写入内核,只能把它的保护给咔嚓掉了,不过--如果做完了手脚但不还原写保护属性的话,极有可能会BOSD. /================== ...