Android studio实现自定义圆形进度条 带刻度进度条 计步效果 时速表 水波纹效果

news2024/10/7 18:29:21

目录

        • 原文链接
        • 效果图
        • values /
        • layout /
        • activity

原文链接

效果图

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
点击重置后:
在这里插入图片描述
该项目总共实现了三种圆形进度条效果

  1. CircleProgress:圆形进度条,可以实现仿 QQ 健康计步器的效果,支持配置进度条背景色、宽度、起始角度,支持进度条渐变
  2. DialProgress:类似 CircleProgress,但是支持刻度
  3. WaveProgress:实现了水波纹效果的圆形进度条,不支持渐变和起始角度配置,如需此功能可参考 CircleProgress 自行实现。
    所有进度条都是可以手动触摸变化百分比的
    我的代码和依赖,我没有加leakcanary库,没有app.activity
    依赖是出现报错后自己添加的,不一定适用所有项目
 buildTypes {
   
        debug {
   
            buildConfigField "boolean", "DEBUG", "true"

        }
        release {
   
            buildConfigField "boolean", "DEBUG", "false"
            }
  defaultConfig {
   
   buildConfigField "boolean", "DEBUG", "true"
   }

values /

attrs.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <!-- 是否开启抗锯齿 -->
    <attr name="antiAlias" format="boolean" />
    <!-- 圆弧起始角度,3点钟方向为0,顺时针递增,小于0或大于360进行取余 -->
    <attr name="startAngle" format="float" />
    <!-- 圆弧度数 -->
    <attr name="sweepAngle" format="float" />
    <!-- 设置动画时间 -->
    <attr name="animTime" format="integer" />
    <!-- 绘制内容的数值 -->
    <attr name="maxValue" format="float" />
    <attr name="value" format="float" />
    <!-- 绘制内容的单位 -->
    <attr name="unit" format="string|reference" />
    <attr name="unitSize" format="dimension" />
    <attr name="unitColor" format="color|reference" />
    <!-- 绘制内容相应的提示语 -->
    <attr name="hint" format="string|reference" />
    <attr name="hintSize" format="dimension" />
    <attr name="hintColor" format="color|reference" />
    <!-- 精度,默认为0 -->
    <attr name="precision" format="integer" />
    <attr name="valueSize" format="dimension" />
    <attr name="valueColor" format="color|reference" />
    <!-- 圆弧颜色,设置多个可实现渐变 -->
    <attr name="arcColor1" format="color|reference" />
    <attr name="arcColor2" format="color|reference" />
    <attr name="arcColor3" format="color|reference" />
    <!-- 背景圆弧颜色,默认白色 -->
    <attr name="bgArcColor" format="color|reference" />
    <!-- 圆弧宽度 -->
    <attr name="arcWidth" format="dimension" />
    <!-- 圆弧颜色, -->
    <attr name="arcColors" format="color|reference" />
    <!-- 文字的偏移量。相对于圆半径而言,默认三分之一 -->
    <attr name="textOffsetPercentInRadius" format="float" />

    <!-- 圆形进度条 -->
    <declare-styleable name="CircleProgressBar">
        <attr name="antiAlias" />
        <attr name="startAngle" />
        <attr name="sweepAngle" />
        <attr name="animTime" />
        <attr name="maxValue" />
        <attr name="value" />
        <attr name="precision" />
        <attr name="valueSize" />
        <attr name="valueColor" />
        <attr name="textOffsetPercentInRadius" />
        <!-- 绘制内容相应的提示语 -->
        <attr name="hint" />
        <attr name="hintSize" />
        <attr name="hintColor" />
        <!-- 绘制内容的单位 -->
        <attr name="unit" />
        <attr name="unitSize" />
        <attr name="unitColor" />
        <!-- 圆弧宽度 -->
        <attr name="arcWidth" />
        <attr name="arcColors" />
        <!-- 背景圆弧颜色 -->
        <attr name="bgArcColor" />
        <!-- 背景圆弧宽度 -->
        <attr name="bgArcWidth" format="dimension" />
    </declare-styleable>

    <declare-styleable name="DialProgress">
        <attr name="antiAlias" />
        <attr name="startAngle" />
        <attr name="sweepAngle" />
        <attr name="animTime" />
        <attr name="maxValue" />
        <attr name="value" />
        <attr name="precision" />
        <attr name="valueSize" />
        <attr name="valueColor" />
        <attr name="textOffsetPercentInRadius" />
        <!-- 绘制内容的单位 -->
        <attr name="unit" />
        <attr name="unitSize" />
        <attr name="unitColor" />
        <!-- 绘制内容相应的提示语 -->
        <attr name="hint" />
        <attr name="hintSize" />
        <attr name="hintColor" />
        <!-- 圆弧的宽度 -->
        <attr name="arcWidth" />
        <!-- 刻度的宽度 -->
        <attr name="dialWidth" format="dimension|reference" />
        <!-- 刻度之间的间隔 -->
        <attr name="dialIntervalDegree" format="integer" />
        <!-- 圆弧颜色, -->
        <attr name="arcColors" />
        <!-- 背景圆弧线颜色 -->
        <attr name="bgArcColor" />
        <!-- 刻度线颜色 -->
        <attr name="dialColor" format="color|reference" />
    </declare-styleable>

    <declare-styleable name="WaveProgress">
        <!-- 是否开启抗锯齿 -->
        <attr name="antiAlias" />
        <!-- 深色水波动画时间 -->
        <attr name="darkWaveAnimTime" format="integer" />
        <!-- 浅色水波动画时间 -->
        <attr name="lightWaveAnimTime" format="integer" />
        <!-- 最大值 -->
        <attr name="maxValue" />
        <!-- 当前值 -->
        <attr name="value" />
        <attr name="valueColor" />
        <attr name="valueSize" />
        <!-- 绘制内容相应的提示语 -->
        <attr name="hint" />
        <attr name="hintSize" />
        <attr name="hintColor" />
        <!-- 圆环宽度 -->
        <attr name="circleWidth" format="dimension" />
        <!-- 圆环颜色 -->
        <attr name="circleColor" format="color|reference" />
        <!-- 背景圆环颜色 -->
        <attr name="bgCircleColor" format="color|reference" />
        <!-- 锁定水波不随圆环进度改变,默认锁定在50%-->
        <attr name="lockWave" format="boolean" />
        <!-- 水波数量 -->
        <attr name="waveNum" format="integer" />
        <!-- 水波高度,峰值和谷值之和 -->
        <attr name="waveHeight" format="dimension" />
        <!-- 深色水波颜色 -->
        <attr name="darkWaveColor" format="color|reference" />
        <!-- 是否显示浅色水波 -->
        <attr name="showLightWave" format="boolean" />
        <!-- 浅色水波颜色 -->
        <attr name="lightWaveColor" format="color|reference" />
        <!-- 浅色水波的方向 -->
        <attr name="lightWaveDirect" format="enum">
            <enum name="L2R" value="0" />
            <enum name="R2L" value="1" />
        </attr>
    </declare-styleable>
</resources>

color.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="black">#FF000000</color>
    <color name="white">#FFFFFFFF</color>
    <color name="colorPrimary">#3F51B5</color>
    <color name="colorPrimaryDark">#303F9F</color>
    <color name="colorAccent">#FF4081</color>

    <color name="dark">#803cbcb7</color>
    <color name="light">#800de6e8</color>

    <color name="green">#00FF00</color>
    <color name="blue">#EE9A00</color>
    <color name="red">#EE0000</color>

    <integer-array name="gradient_arc_color">
        <item>@color/green</item>
        <item>@color/blue</item>
        <item>@color/red</item>
    </integer-array>
</resources>

dimens.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <dimen name="small">5dp</dimen>
    <dimen name="medium">10dp</dimen>
    <dimen name="normal">15dp</dimen>
    <dimen name="large">20dp</dimen>
    <dimen name="xlarge">25dp</dimen>
    <dimen name="xxlarge">30dp</dimen>

    <!-- text size -->
    <dimen name="text_size_35">35sp</dimen>
    <dimen name="text_size_34">34sp</dimen>
    <dimen name="text_size_33">33sp</dimen>
    <dimen name="text_size_32">32sp</dimen>
    <dimen name="text_size_31">31sp</dimen>
    <dimen name="text_size_30">30sp</dimen>
    <dimen name="text_size_29">29sp</dimen>
    <dimen name="text_size_28">28sp</dimen>
    <dimen name="text_size_26">26sp</dimen>
    <dimen name="text_size_25">25sp</dimen>
    <dimen name="text_size_24">24sp</dimen>
    <dimen name="text_size_23">23sp</dimen>
    <dimen name="text_size_22">22sp</dimen>
    <dimen name="text_size_21">21sp</dimen>
    <dimen name="text_size_20">20sp</dimen>
    <dimen name="text_size_19">19sp</dimen>
    <dimen name="text_size_18">18sp</dimen>
    <dimen name="text_size_17">17sp</dimen>
    <dimen name="text_size_16">16sp</dimen>
    <dimen name="text_size_15">15sp</dimen>
    <dimen name="text_size_14">14sp</dimen>
    <dimen name="text_size_13">13sp</dimen>
    <dimen name="text_size_12">12sp</dimen>
    <dimen name="text_size_11">11sp</dimen>
    <dimen name="text_size_10">10sp</dimen>
    <dimen name="text_size_9">9sp</dimen>
    <dimen name="text_size_8">8sp</dimen>
    <dimen name="text_size_7">7sp</dimen>

    <!-- Default screen margins, per the Android Design guidelines. -->
    <dimen name="activity_horizontal_margin">16dp</dimen>
    <dimen name="activity_vertical_margin">16dp</dimen>
</resources>

layout /

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.circularwaterripple.MainActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <Button
            android:id="@+id/btn_reset_all"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="重置" />

        <com.example.circularwaterripple.CircleProgress
            android:id="@+id/circle_progress_bar1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            app:antiAlias="true"
            app:arcWidth="@dimen/small"
            app:bgArcColor="@color/colorAccent"
            app:bgArcWidth="@dimen/small"
            app:hint="截止当前已走"
            app:hintSize="15sp"
            app:maxValue="10000"
            app:startAngle="135"
            app:sweepAngle="270"
            app:unit="步"
            app:unitSize="15sp"
            app:value="10000"
            app:valueSize="25sp"/>

        <com.example.circularwaterripple.CircleProgress
            android:id="@+id/circle_progress_bar2"
            android:layout_width="100dp"
            android:layout_height="200dp"
            android:layout_gravity="center_horizontal"
            app:antiAlias="true"
            app:arcWidth="@dimen/small"
            app:bgArcColor="@color/colorAccent"
            app:bgArcWidth="@dimen/small"
            app:hint="百分比"
            app:hintSize="@dimen/text_size_15"
            app:maxValue="100"
            app:startAngle="135"
            app:sweepAngle="270"
            app:textOffsetPercentInRadius="0.5"
            app:unit="%"
            app:unitSize="@dimen/text_size_15"
            app:value="75"
            app:valueSize="@dimen/text_size_20"
            tools:ignore="MissingClass" />

        <com.example.circularwaterripple.CircleProgress
            android:id="@+id/circle_progress_bar3"
            android:layout_width="200dp"
            android:layout_height="200dp"
            android:layout_gravity="center_horizontal"
            app:antiAlias="true"
            app:arcWidth="@dimen/small"
            app:bgArcColor="@android:color/darker_gray"
            app:bgArcWidth="@dimen/small"
            app:hint="当前进度"
            app:hintSize="@dimen/text_size_25"
            app:maxValue="100"
            app:startAngle="270"
            app:sweepAngle="360"
            app:unit="%"
            app:unitSize="@dimen/text_size_25"
            app:value="100"
            app:valueSize="@dimen/text_size_35" />

        <com.example.circularwaterripple.DialProgress
            android:id="@+id/dial_progress_bar"
            android:layout_width="300dp"
            android:layout_height="300dp"
            android:layout_gravity="center_horizontal"
            android:padding="@dimen/medium"
            app:animTime="1000"
            app:arcColors="@array/gradient_arc_color"
            app:arcWidth="@dimen/large"
            app:dialIntervalDegree="3"
            app:dialWidth="2dp"
            app:hint="当前时速"
            app:hintSize="@dimen/text_size_25"
            app:maxValue="300"
            app:startAngle="135"
            app:sweepAngle="270"
            app:unit="km/h"
            app:unitSize="@dimen/text_size_25"
            app:value="300"
            app:valueSize="@dimen/text_size_35" />

        <com.example.circularwaterripple.WaveProgress
            android:id="@+id/wave_progress_bar"
            android:layout_width="300dp"
            android:layout_height="300dp"
            android:layout_gravity="center_horizontal"
            app:darkWaveAnimTime="1000"
            app:darkWaveColor="@color/dark"
            app:lightWaveAnimTime="2000"
            app:lightWaveColor="@color/light"
            app:lightWaveDirect="R2L"
            app:lockWave="false"
            app:valueSize="@dimen/text_size_35"
            app:waveHeight="30dp"
            app:waveNum="1"
            tools:ignore="ExtraText" />
    </LinearLayout>
</ScrollView>

activity.test.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/976711.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

linux jar包class热部署 工具 arthas安装及使用

在不改变类、方法 的前提下&#xff0c;在方法中对业务逻辑做处理 或 打日志等情况下使用。 建议线上日志调试时使用&#xff1a; arthas安装 1. 下载文件 arthas-packaging-3.7.1-bin.zip https://arthas.aliyun.com 2. 服务器安装arthas 2.1 服务器指定目录下创建目录 c…

双系统备忘

1.装了双系统&#xff0c; 找不到ubuntu,只有windows 从windows启动cmd bcdedit /set “{bootmgr}” path \EFI\ubuntu\grubx64.efi双系统分别装在两块磁盘&#xff0c; windows装在硬盘0&#xff0c; ubuntu装在硬盘1 然后启动是从硬盘0读的boot, 现在我要移除windows硬盘0…

Vue + Element UI 前端篇(一):搭建开发环境

Vue Element UI 实现权限管理系统 前端篇&#xff08;一&#xff09;&#xff1a;搭建开发环境 技术基础 开发之前&#xff0c;请先熟悉下面的4个文档 vue.js2.0中文, 优秀的JS框架vue-router, vue.js 配套路由vuex&#xff0c;vue.js 应用状态管理库Element&#xff0c;饿…

基环树和点度数相关的计数:CF1863G

https://codeforces.com/contest/1863/problem/G 首先建图&#xff0c;然后分析出交换在图上的变化&#xff0c;发现每条点最多只有一个入边标粗&#xff0c;求最终形态。 首先可以猜答案为 ∏ v ( i n v 1 ) \prod_{v}(\mathrm{in}_v 1) ∏v​(inv​1)&#xff0c;但是环…

FOXBORO P0926KP控制器

应用领域&#xff1a; FOXBORO P0926KP 控制器广泛应用于工业自动化和过程控制领域&#xff0c;包括化工、石油和天然气、电力、制造业等各种行业。 控制能力&#xff1a; 该控制器具有高性能的控制能力&#xff0c;可执行复杂的控制策略和算法&#xff0c;以确保工业过程的高…

监控 -- linux中的一些系统性能状态指令、Prometheus

目录 监控查看性能相关命令Prometheus1、安装和配置2、将 NFS服务器和LB服务器作为exporter采集数据3、在prometheus server里添加安装exporter程序的服务器 grafana出图工具 监控 监控的目的是获取数据&#xff0c;通过数据分析了解机器是否正常运行 查看性能相关命令 查看c…

R7 7840U和r7 6800u差距 锐龙R77840U和6800u对比

锐龙7 7840U 采用Zen3架构、8核心16线程&#xff0c;基准频率疑似3.3GHz&#xff0c;同样集成RDNA3架构核显Radeon 780M&#xff0c;也是12个CU单元 r7 7840U 的处理器在 Cinebench R23 中多核跑分 14825 分 选R7 7840U还是r7 6800u这些点很重要 http://www.adiannao.cn/dy r…

CMAK学习

VS中的cmake_cmake vs_今天也要debug的博客-CSDN博客 利用vs2017 CMake开发跨平台C项目实战_cmake vs2017_神气爱哥的博客-CSDN博客 【【入门】在VS中使用CMake管理若干程序】https://www.bilibili.com/video/BV1iz4y117rZ?vd_source0aeb782d0b9c2e6b0e0cdea3e2121eba

Nacos服务健康检查与服务变动事件发布源码解析

目录 1 快速入门使用2 源码解析2.1 环境准备2.2 查看实例列表源码分析2.3 nacos与zk的不同 :2.4 nacos服务发现2.5 nacos的心跳机制和服务健康检查的逻辑 1 快速入门使用 SpringCloud Nacos配置中心&#xff1a;https://blog.csdn.net/ZGL_cyy/article/details/113621565 Sprin…

前端瀑布流效果

先看效果 <!DOCTYPE html> <html lang"en"> <head><meta charset"UTF-8"><meta name"viewport" content"widthdevice-width, initial-scale1.0"><title>Document</title> </head> &l…

MT8788安卓核心板详细参数_MTK安卓主板开发板智能通讯模块

MT8788安卓核心板集成了一个高效的12nm SoC&#xff0c;内置4G LTE调制解调器&#xff0c;将强大的硬件与到处可连接的全面功能设计相结合。 MTK8788智能终端具备许多功能&#xff0c;包括4G、2.4G/5G双频WiFi、蓝牙4.2BLE、2.5W功放、USB、mipi屏接口、三路摄像头接口、GPS和…

Day 39 动态规划part02 : 62.不同路径 63. 不同路径 II

62. 不同路径 一个机器人位于一个 m x n 网格的左上角 &#xff08;起始点在下图中标记为 “Start” &#xff09;。 机器人每次只能向下或者向右移动一步。机器人试图达到网格的右下角&#xff08;在下图中标记为 “Finish” &#xff09;。 问总共有多少条不同的路径&#xf…

Pandas小白入门散记(3)---Series.str--源代码定位问题

文章目录 问题点原因解释 碰到了&#xff0c;一个错误&#xff0c;debug才定位到问题&#xff0c;记录一下。 本次最大收获是&#xff0c;pandas果然代码逻辑复杂&#xff0c;一个小小的异常捕捉&#xff0c;处处是门道。。。。。。 希望本次浅显的代码阅读过程&#xff0c;给…

使用element-ui导航,进入对应的三级页面菜单保持点击状态

1.注意事项 01.路由中使用了keepAlive属性&#xff0c;要用keepAlive&#xff1a;true&#xff0c;不能等于false&#xff0c;使用false页面会刷新 2.使用的方法 NavMenu 导航菜单 3.项目实例 <template><div class"policy-home"><div class"…

QHttpServer

QLineEdit-----输入提示 改动CmakeLists.txt 在帮助–索引查找QHttpServer 改动CmakeLists.txt&#xff0c;有三处改动 在谷歌浏览器测试&#xff0c;输入127.0.0.1/api/login 测试代码 #include<QCoreApplication> #include <QHttpServer> //http服务器 int m…

查看显卡显存

1、cmd或者终端输入&#xff1a; nvidia-smi4096为显存总大小&#xff0c;1228为目前使用的显存大小 2、或者在编辑器中直接安装gpustat包进行查看 pip install gpustat gpustat -cpuigpustat -cpui用于查看当前GPU使用情况 更直观&#xff1f; CtrlC 退出

小白学go基础06-了解切片实现原理并高效使用

slice&#xff0c;中文多译为切片&#xff0c;是Go语言在数组之上提供的一个重要的抽象数据类型。在Go语言中&#xff0c;对于绝大多数需要使用数组的场合&#xff0c;切片实现了完美替代。并且和数组相比&#xff0c;切片提供了更灵活、更高效的数据序列访问接口。 切片究竟是…

JavaScript-----函数

目录 前言&#xff1a; JavaScript函数 1. 定义函数 构造函数 2. 调用函数 函数的自执行 3. 函数的参数 4. 函数返回值 5. 作用域 6. 匿名函数 7. this指向性问题&#xff08;重点&#xff09; 7.1 this的性质 7.2 call的用法 7.3 apply的用法 7.4 bind的用法&a…

KMP超高效匹配算法

简介&#xff1a; KMP算法是一种改进的字符串匹配算法&#xff0c;其中&#xff0c;KMP算法的运用核心是利用匹配失败后的信息&#xff0c;最大进度的减少模式串与目标串的匹配次数以达到快速匹配的效果。算法与暴力求解的改进在于每当一趟匹配过程中出现的字符比较不相等时&am…

无涯教程-JavaScript - NOW函数

描述 NOW函数返回当前日期和时间的序列号。 语法 NOW ()争论 NOW函数语法没有参数。 Notes 如果在输入功能之前单元格格式为"常规",则Excel会更改单元格格式,使其与您的区域设置的日期和时间格式匹配。您可以使用功能区"主页"options卡"数字&quo…