Android开发 自定义View_白色圆型涟漪动画View
代码:
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的更多相关文章
- Android开发自定义View
Android中View组件的作用类似于Swing变成中的JPanel,它只是一个空白的矩形区域,View组件中没有任何内容.对于Android应用的其他UI组件来说,它们都继承了View组件,然后在 ...
- android 开发-自定义多节点进度条显示
看效果图: 里面的线段颜色和节点图标都是可以自定义的. main.xml <RelativeLayout xmlns:android="http://schemas.android.c ...
- [android 开发篇] 易白教程网址
http://www.yiibai.com/android/android_bluetooth.html
- android开发 自定义图文混排控件
功能:图文混排,可自动缩放字体,如图: 单点触控使用的代码来自:http://blog.csdn.net/xiaanming/article/details/42833893 谢谢博主! 在该dem ...
- Android开发之仿微信显示更多文字的View
最近开发需求中要模仿微信朋友圈文章的展开收起功能,网上找了找,发现都有问题,于是乎自己在前辈的基础上进行了一定量的修改,下边将源码贴出来供大家参考:1.主Activity布局文件就不粘贴了,很简单,就 ...
- Android开发 - 掌握ConstraintLayout(十一)复杂动画!如此简单!
介绍 本系列我们已经介绍了ConstraintLayout的基本用法.学习到这里,相信你已经熟悉ConstraintLayout的基本使用了,如果你对它的用法还不了解,建议您先阅读我之前的文章. 使用 ...
- Android开发UI之给ListView设置布局动画效果
1.通过JAVA代码添加,资源文件基本上不修改 XML文件,只添加了一个ListView,就不贴XML文件的代码了. java代码: public class MainActivity extends ...
- Android开发之自定义组件和接口回调
说到自定义控件不得不提的就是接口回调,在Android开发中接口回调用的还是蛮多的.在这篇博客开始的时候呢,我想聊一下iOS的自定义控件.在iOS中自定义控件的思路是继承自UIView, 在UIVie ...
- 在Eclipse下搭建Android开发环境教程
我们昨天向各位介绍了<在NetBeans上搭建Android SDK环境>,前不久也介绍过<在MyEclipse 8.6上搭建Android开发环境>, 都受到了读者的欢迎.但 ...
随机推荐
- exe自启动的几种方式
1 注册表启动项目RUN (注册路径 HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\Windows\CurrentVersion\Run) 2 计划任务 比较少见这种方式 ...
- linux学习的任督二脉-进程调度和内存管理
转自 宋宝华老师的博客原文:https://blog.csdn.net/21cnbao/article/details/77505330 内功心法 学习或遇到问题时,反过来主动思考如果我是设计者,我会 ...
- MFS分布式文件系统【1】概述
注:以下内容来自互联网 MFS文件系统概论 MFS是linux下的开源存储系统,是由波兰人开发的.MFS文件系统能够实现RAID的功能,不但能够节约存储成本,而且不逊于专业的存储系统,能够实现在线扩展 ...
- JAVA API 实现hdfs文件操作
java api 实现hdfs 文件操作会出现错误提示: Permission denied: user=hp, access=WRITE, inode="/":hdfs:supe ...
- [已解决]windows安装docker的问题
windows下载安装docker出现的问题 进入powershell后输入docker --version报错: could not read CA certificate "C:\\Us ...
- Excel的线程 与 SynchronizationContext的实现
COM组件的线程模型与Excel多线程的背景知识 COM组件的线程模型被称之为Apartment模型,COM对象初始化时其执行上下文(Execution Context),他要么和单个线程关联STA( ...
- android Intent和IntentFilter
android的应用程序包含三种重要的组件:Activity.Service.BroadcastReceiver,应用程序采用一致的方式来启动他们——都是依靠Intent来进行启动.Intent就封装 ...
- leetcood学习笔记-226- 翻转二叉树
题目描述: 第一次提交: class Solution(object): def invertTree(self, root): """ :type root: Tree ...
- java-----Long转换为 int , string
int: 1.调用intValue()方法 long ll = 300000; int ii= new Long(ll).intValue(); 2.先把long转换成字符串String,然后在转行成 ...
- __str__方法
"""str()就是可以自定义输出返回值,必须是str字符串""" class Dog: def __init__(self, name): ...