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开发环境>, 都受到了读者的欢迎.但 ...
随机推荐
- TIKA环境配置
本章将指导完成设置Apache Tika在Windows和Linux的配置过程.用户管理是必要的,同时安装了Apache Tika. 系统要求 JDK Java SE 2 JDK 1.6 或以上 内存 ...
- BOM 3.1 location对象 | history对象 | navigator对象 | 定时器 | 三大系列
JavaScript分三个部分: 1. ECMAScript标准---基本语法 2. DOM--->Document Object Model 文档对象模型,操作页面元素的 3. BOM---& ...
- 用python+tushare获取股票前复权后复权行情数据
接口名称 :pro_bar 接口说明 :复权行情通过通用行情接口实现,利用Tushare Pro提供的复权因子进行计算,目前暂时只在SDK中提供支持,http方式无法调取. Python SDK版本要 ...
- 「CSP-S 2019」树的重心
题目 考场上送\(75pts\)真实良心,正解不难:考虑直接对于每一个点算割掉多少条边能使得这个点成为重心,不难发现对于一个不是重心的点,我们要割掉的那条边一定在那个大于\(\lfloor \frac ...
- USACO 2001 OPEN earthquake /// 最优比例生成树
题目大意: https://www.cnblogs.com/forever97/p/3603572.html 讲解:https://www.jianshu.com/p/d40a740a527e 题解: ...
- jsk
题目描述 码队的女朋友非常喜欢玩某款手游,她想让码队带他上分.但是码队可能不会带青铜段位的女朋友上分,因为码队的段位太高(已经到达王者),恐怕不能和他的女朋友匹配游戏. 码队的女朋友有些失落,她希望能 ...
- 在vue中使用高德地图开发,以及AMap的引入?
百度引入BMap ,一个import 即可,可AMap 却报AMap is not difined ? 1.首先在 externals: { "BMap": "BMap& ...
- 我的vscode配置 利用Settings Sync一键安装
{ "prettier.eslintIntegration": true, // 点击保存时,根据 eslint 规则自定修复,同时集成 prettier 到 eslint 中 & ...
- html-基础知识二
form 功能:向服务器传输数据,实现用户和web 服务器的交互 一.表单属性 accept-charset: 规定在提交表单中使用的字符集 action:规定向何处提交表单地址(url) autoc ...
- 2019-4-15-VisualStudio-如何在-NuGet-包里面同时包含-DEBUG-和-RELEASE-的库
title author date CreateTime categories VisualStudio 如何在 NuGet 包里面同时包含 DEBUG 和 RELEASE 的库 lindexi 20 ...