自定义圆形、半圆形ProgressBar

本文介绍如何在Android中创建自定义的圆形和半圆形ProgressBar,使用了RectF、SweepGradient和Canvas等组件,通过示例代码详细阐述了实现过程,包括颜色渐变、圆弧角度控制以及ValueAnimator的应用。
摘要由CSDN通过智能技术生成

最近在做的项目中遇到做圆形、半圆形ProgressBar,先分享给大家
主要用到类:
一、Android RectF类的构造函数参数说明
以下是API中的说明:
public RectF (float left, float top, float right, float bottom)

Added in API level 1
Create a new rectangle with the specified coordinates. Note: no range checking is performed, so the caller must ensure that left <= right and top <= bottom.

Parameters
left The X coordinate of the left side of the rectangle
top The Y coordinate of the top of the rectangle
right The X coordinate of the right side of the rectangle
bottom The Y coordinate of the bottom of the rectangle
比如new一个RecF类:
RectF rf1 = new RectF(100,100,200,200);
则在屏幕中的位置示意图为:

二、SweepGradient的说明与使用
主要实现圆形可颜色渐变进度条

public SweepGradient(float cx, float cy, int[] colors, float[] positions)
Parameters:

cx 渲染中心点x 坐标
cy 渲染中心y 点坐标
colors 围绕中心渲染的颜色数组,至少要有两种颜色值
positions 相对位置的颜色数组,可为null, 若为null,可为null,颜色沿渐变线均匀分布

public SweepGradient(float cx, float cy, int color0, int color1)
Parameters:

cx 渲染中心点x 坐标
cy 渲染中心点y 坐标
color0 起始渲染颜色
color1 结束渲染颜色

三、Canvas
public void draw

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值