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

相关文章

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

Linux中的自定义协议+序列反序列化用法

《Linux中的自定义协议+序列反序列化用法》文章探讨网络程序在应用层的实现,涉及TCP协议的数据传输机制、结构化数据的序列化与反序列化方法,以及通过JSON和自定义协议构建网络计算器的思路,强调分层... 目录一,再次理解协议二,序列化和反序列化三,实现网络计算器3.1 日志文件3.2Socket.hpp

C语言自定义类型之联合和枚举解读

《C语言自定义类型之联合和枚举解读》联合体共享内存,大小由最大成员决定,遵循对齐规则;枚举类型列举可能值,提升可读性和类型安全性,两者在C语言中用于优化内存和程序效率... 目录一、联合体1.1 联合体类型的声明1.2 联合体的特点1.2.1 特点11.2.2 特点21.2.3 特点31.3 联合体的大小1

Android Paging 分页加载库使用实践

《AndroidPaging分页加载库使用实践》AndroidPaging库是Jetpack组件的一部分,它提供了一套完整的解决方案来处理大型数据集的分页加载,本文将深入探讨Paging库... 目录前言一、Paging 库概述二、Paging 3 核心组件1. PagingSource2. Pager3.

springboot自定义注解RateLimiter限流注解技术文档详解

《springboot自定义注解RateLimiter限流注解技术文档详解》文章介绍了限流技术的概念、作用及实现方式,通过SpringAOP拦截方法、缓存存储计数器,结合注解、枚举、异常类等核心组件,... 目录什么是限流系统架构核心组件详解1. 限流注解 (@RateLimiter)2. 限流类型枚举 (

SpringBoot 异常处理/自定义格式校验的问题实例详解

《SpringBoot异常处理/自定义格式校验的问题实例详解》文章探讨SpringBoot中自定义注解校验问题,区分参数级与类级约束触发的异常类型,建议通过@RestControllerAdvice... 目录1. 问题简要描述2. 异常触发1) 参数级别约束2) 类级别约束3. 异常处理1) 字段级别约束

从入门到精通详解LangChain加载HTML内容的全攻略

《从入门到精通详解LangChain加载HTML内容的全攻略》这篇文章主要为大家详细介绍了如何用LangChain优雅地处理HTML内容,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录引言:当大语言模型遇见html一、HTML加载器为什么需要专门的HTML加载器核心加载器对比表二