PathMeasure 自定义view 好看的加载效果

2024-04-17 17:32

本文主要是介绍PathMeasure 自定义view 好看的加载效果,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

根据上一篇PathMeasure的介绍,我们来实现一个好看的 加载效果
在这里插入图片描述
直接贴代码

public class PathMeasureView extends View
{private Paint mPaint = new Paint();private Paint mLinePaint = new Paint(); //坐标系private Bitmap mBitmap;private int width, height;private float len;private float mInnerLenght;private boolean isor = false;Path dst = new Path();Path innerDst = new Path();public PathMeasureView(Context context){this(context, null);}public PathMeasureView(Context context, AttributeSet attrs){this(context, attrs, 0);}public PathMeasureView(Context context, AttributeSet attrs, int defStyleAttr){super(context, attrs, defStyleAttr);mPaint.setStyle(Paint.Style.STROKE);mPaint.setColor(Color.BLACK);mPaint.setStrokeWidth(4);mLinePaint.setStyle(Paint.Style.STROKE);mLinePaint.setColor(Color.RED);mLinePaint.setStrokeWidth(6);}@Overrideprotected void onMeasure(int widthMeasureSpec, int heightMeasureSpec){super.onMeasure(widthMeasureSpec, heightMeasureSpec);width = MeasureSpec.getSize(widthMeasureSpec);height = MeasureSpec.getSize(heightMeasureSpec);//防止过度测量if(!isor){isor=true;Path path = new Path();path.addCircle(width/2, height/2, 50, Path.Direction.CW);path.addCircle(width/2, height/2, 50, Path.Direction.CCW);final PathMeasure pathMeasure = new PathMeasure(path, false);len = pathMeasure.getLength();final PathMeasure pathMeasure1 = new PathMeasure(path, false);//移动到下一个path曲线pathMeasure1.nextContour();mInnerLenght=pathMeasure1.getLength();ValueAnimator animator = ValueAnimator.ofFloat(0, 1);animator.setDuration(1500);animator.setRepeatCount(ValueAnimator.INFINITE);animator.setInterpolator(new LinearInterpolator());animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener(){@Overridepublic void onAnimationUpdate(ValueAnimator animation){dst.reset();innerDst.reset();float start = (float) ((len * (float) animation.getAnimatedValue()) - ((0.5 - Math.abs((float) animation.getAnimatedValue() - 0.5)) * len));pathMeasure.getSegment(start, (len * (float) animation.getAnimatedValue()), dst, true);//pathMeasure.getSegment(0, (len * (float) animation.getAnimatedValue()), dst, true);float start1 = (float) ((mInnerLenght * (float) animation.getAnimatedValue()) - ((0.5 - Math.abs((float) animation.getAnimatedValue() - 0.5)) * mInnerLenght));pathMeasure1.getSegment(start1, (mInnerLenght * (float) animation.getAnimatedValue()), innerDst, true);invalidate();}});animator.start();}}@Overrideprotected void onDraw(Canvas canvas){super.onDraw(canvas);canvas.drawPath(dst, mLinePaint);canvas.drawPath(innerDst, mLinePaint);}private float[] pos = new float[2];private float[] tan = new float[2];
}

这篇关于PathMeasure 自定义view 好看的加载效果的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/912433

相关文章

kafka自定义分区器使用详解

《kafka自定义分区器使用详解》本文介绍了如何根据企业需求自定义Kafka分区器,只需实现Partitioner接口并重写partition()方法,示例中,包含cuihaida的数据发送到0号分区... 目录kafka自定义分区器假设现在有一个需求使用分区器的方法总结kafka自定义分区器根据企业需求

springboot+mybatis一对多查询+懒加载实例

《springboot+mybatis一对多查询+懒加载实例》文章介绍了如何在SpringBoot和MyBatis中实现一对多查询的懒加载,通过配置MyBatis的`fetchType`属性,可以全局... 目录springboot+myBATis一对多查询+懒加载parent相关代码child 相关代码懒

MyBatis延迟加载与多级缓存全解析

《MyBatis延迟加载与多级缓存全解析》文章介绍MyBatis的延迟加载与多级缓存机制,延迟加载按需加载关联数据提升性能,一级缓存会话级默认开启,二级缓存工厂级支持跨会话共享,增删改操作会清空对应缓... 目录MyBATis延迟加载策略一对多示例一对多示例MyBatis框架的缓存一级缓存二级缓存MyBat

通过React实现页面的无限滚动效果

《通过React实现页面的无限滚动效果》今天我们来聊聊无限滚动这个现代Web开发中不可或缺的技术,无论你是刷微博、逛知乎还是看脚本,无限滚动都已经渗透到我们日常的浏览体验中,那么,如何优雅地实现它呢?... 目录1. 早期的解决方案2. 交叉观察者:IntersectionObserver2.1 Inter

C#中通过Response.Headers设置自定义参数的代码示例

《C#中通过Response.Headers设置自定义参数的代码示例》:本文主要介绍C#中通过Response.Headers设置自定义响应头的方法,涵盖基础添加、安全校验、生产实践及调试技巧,强... 目录一、基础设置方法1. 直接添加自定义头2. 批量设置模式二、高级配置技巧1. 安全校验机制2. 类型

SpringBoot AspectJ切面配合自定义注解实现权限校验的示例详解

《SpringBootAspectJ切面配合自定义注解实现权限校验的示例详解》本文章介绍了如何通过创建自定义的权限校验注解,配合AspectJ切面拦截注解实现权限校验,本文结合实例代码给大家介绍的非... 目录1. 创建权限校验注解2. 创建ASPectJ切面拦截注解校验权限3. 用法示例A. 参考文章本文

Vite 打包目录结构自定义配置小结

《Vite打包目录结构自定义配置小结》在Vite工程开发中,默认打包后的dist目录资源常集中在asset目录下,不利于资源管理,本文基于Rollup配置原理,本文就来介绍一下通过Vite配置自定义... 目录一、实现原理二、具体配置步骤1. 基础配置文件2. 配置说明(1)js 资源分离(2)非 JS 资

聊聊springboot中如何自定义消息转换器

《聊聊springboot中如何自定义消息转换器》SpringBoot通过HttpMessageConverter处理HTTP数据转换,支持多种媒体类型,接下来通过本文给大家介绍springboot中... 目录核心接口springboot默认提供的转换器如何自定义消息转换器Spring Boot 中的消息

SpringBoot加载profile全面解析

《SpringBoot加载profile全面解析》SpringBoot的Profile机制通过多配置文件和注解实现环境隔离,支持开发、测试、生产等不同环境的灵活配置切换,无需修改代码,关键点包括配置文... 目录题目详细答案什么是 Profile配置 Profile使用application-{profil

Python自定义异常的全面指南(入门到实践)

《Python自定义异常的全面指南(入门到实践)》想象你正在开发一个银行系统,用户转账时余额不足,如果直接抛出ValueError,调用方很难区分是金额格式错误还是余额不足,这正是Python自定义异... 目录引言:为什么需要自定义异常一、异常基础:先搞懂python的异常体系1.1 异常是什么?1.2