自定义进度条渐变色View
package com.jianke.stepCounter.Activity; import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.graphics.Shader;
import android.graphics.SweepGradient;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View; import com.jianke.doctor.R; /**
* @author xiaanming
*
*/
@SuppressLint("DrawAllocation")
public class RoundProgressBar extends View { private Paint paint; public int roundColor; public int roundProgressColor; private int textColor;
private float textSize; private float roundWidth; private int max; private int progress;
public boolean textIsDisplayable; private int style; public static final int STROKE = 0;
public static final int FILL = 1; public RoundProgressBar(Context context) {
this(context, null);
} public RoundProgressBar(Context context, AttributeSet attrs) {
this(context, attrs, 0);
} public RoundProgressBar(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle); paint = new Paint(); TypedArray mTypedArray = context.obtainStyledAttributes(attrs,
R.styleable.RoundProgressBar); roundColor = mTypedArray.getColor(
R.styleable.RoundProgressBar_roundColor, Color.RED);
roundProgressColor = mTypedArray.getColor(
R.styleable.RoundProgressBar_roundProgressColor, Color.GREEN);
textColor = mTypedArray.getColor(
R.styleable.RoundProgressBar_textColor0, Color.GREEN);
textSize = mTypedArray.getDimension(
R.styleable.RoundProgressBar_textSize0, 15);
roundWidth = mTypedArray.getDimension(
R.styleable.RoundProgressBar_roundWidth, 5);
max = mTypedArray.getInteger(R.styleable.RoundProgressBar_max, 100);
textIsDisplayable = mTypedArray.getBoolean(
R.styleable.RoundProgressBar_textIsDisplayable, true);
style = mTypedArray.getInt(R.styleable.RoundProgressBar_style, 0); mTypedArray.recycle();
} @Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas); /***/
int centre = getWidth() / 2;
int radius = (int) (centre - roundWidth / 2);
paint.setColor(getResources().getColor(R.color.proessround));
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(roundWidth);
paint.setAntiAlias(true);
paint.setShader(null);
canvas.drawCircle(centre, centre, radius, paint);
paint.setStrokeWidth(0);
paint.setColor(textColor);
paint.setTextSize(textSize);
paint.setTypeface(Typeface.DEFAULT_BOLD);
int percent = (int) (((float) progress / (float) max) * 100);
float textWidth = paint.measureText(percent + "%"); if (textIsDisplayable && percent != 0 && style == STROKE) {
canvas.drawText(percent + "%", centre - textWidth / 2, centre
+ textSize / 2, paint);
} paint.setStrokeWidth(roundWidth);
// paint.setColor(roundProgressColor);
int[] mColors = new int[] {// 渐变色数组
0xFF0da7ff, 0xFF31da41, 0xFF31da41, 0xFF0da7ff ,0xFF0da7ff };
Shader sg = new SweepGradient(0, 0, mColors, null); SweepGradient sg2 = new SweepGradient(centre, centre, getResources()
.getColor(R.color.proessstartcolor), getResources().getColor(
R.color.proessendcolor));
paint.setShader(sg);
RectF oval = new RectF(centre - radius, centre - radius, centre
+ radius, centre + radius); switch (style) {
case STROKE: {
paint.setStyle(Paint.Style.STROKE);
canvas.drawArc(oval, -90, 360 * progress / max, false, paint); // ���ݽ��Ȼ�Բ��
break;
}
case FILL: {
paint.setStyle(Paint.Style.FILL_AND_STROKE);
if (progress != 0)
canvas.drawArc(oval, 0, 360 * progress / max, true, paint); // ���ݽ��Ȼ�Բ��
break;
}
}
} public synchronized int getMax() {
return max;
} /**
* @param max
*/
public synchronized void setMax(int max) {
if (max < 0) {
throw new IllegalArgumentException("max not less than 0");
}
this.max = max;
} /**
* @return
*/
public synchronized int getProgress() {
return progress;
} /**
*
* @param progress
*/
public synchronized void setProgress(int progress) {
if (progress < 0) {
throw new IllegalArgumentException("progress not less than 0");
}
if (progress > max) {
progress = max;
}
if (progress <= max) {
this.progress = progress;
postInvalidate();
} } public int getCricleColor() {
return roundColor;
} public void setCricleColor(int cricleColor) {
this.roundColor = cricleColor;
} public int getCricleProgressColor() {
return roundProgressColor;
} public void setCricleProgressColor(int cricleProgressColor) {
this.roundProgressColor = cricleProgressColor;
} public int getTextColor() {
return textColor;
} public void setTextColor(int textColor) {
this.textColor = textColor;
} public float getTextSize() {
return textSize;
} public void setTextSize(float textSize) {
this.textSize = textSize;
} public float getRoundWidth() {
return roundWidth;
} public void setRoundWidth(float roundWidth) {
this.roundWidth = roundWidth;
} }
使用方法:
final RoundProgressBar fff = new RoundProgressBar(
StepCounterHomePageActivity.this);
fff.setRoundWidth(boardwidth);
fff.roundColor = getResources().getColor(R.color.proessround);
fff.setClickable(false);
fff.textIsDisplayable = false;
relativeLayout2.addView(fff);
自定义进度条渐变色View的更多相关文章
- android113 自定义进度条
MainActivity: package com.itheima.monitor; import android.os.Bundle; import android.app.Activity; im ...
- 自定义进度条PictureProgressBar——从开发到开源发布全过程
自定义进度条PictureProgressBar——从开发到开源发布全过程 出处: 炎之铠邮箱:yanzhikai_yjk@qq.com 本文原创,转载请注明本出处! 本项目JCenter地址:htt ...
- android 自定义进度条颜色
android 自定义进度条颜色 先看图 基于产品经理各种自定义需求,经过查阅了解,下面是自己对Android自定义进度条的学习过程! 这个没法了只能看源码了,还好下载了源码, sources\b ...
- Qt之模型/视图(自定义进度条)
简述 在之前的章节中分享过关于QHeaderView表头排序.添加复选框等内容,相信大家模型/视图.自定义风格有了一定的了解,下面我们来分享一个更常用的内容-自定义进度条. 实现方式: 从QAbstr ...
- C# 根据BackgroundWoker异步模型和ProgressBar控件,自定义进度条控件
前言 程序开发过程中,难免会有的业务逻辑,或者算法之类产生让人能够感知的耗时操作,例如循环中对复杂逻辑处理;获取数据库百万乃至千万级数据;http请求的时候等...... 用户在使用UI操作并不知道程 ...
- BitBlt()函数实现带数字百分比进度条控件、静态文本(STATIC)控件实现的位图进度条、自定义进度条控件实现七彩虹颜色带数字百分比
Windows API BitBlt()函数实现带数字百分比进度条控件. 有两个例子:一用定时器实现,二用多线程实现. 带有详细注解. 此例是本人原创,绝对是网上稀缺资源(本源码用Windows AP ...
- iOS 自定义进度条
自定义条形进度条(iOS) ViewController.m文件 #import "ViewController.h" @interface ViewController () @ ...
- Android_自定义进度条
转载:http://blog.csdn.net/lmj623565791/article/details/43371299 ,本文出自:[张鸿洋的博客] 1.概述 最近需要用进度条,秉着不重复造轮子的 ...
- 最简单的android自定义进度条样式
一.自定义圆形进度条样式 1.在安卓项目drawable目录下新建一个xml文件如下:<?xml version="1.0" encoding="utf-8&quo ...
随机推荐
- 通过SSH克隆远程仓库(GitLab)到本地
由于不是任何用户都能从远程仓库克隆到本地的,也是需要鉴别的,因此本地需要用git bash 创建一个公钥,而远程仓库也要把这个公钥保存下来,进而本地才可以从远程download.主要步骤如下: 1.首 ...
- linux shell实现 URL 编码/解码方法
(1)编码的两种方法 # echo '手机' | tr -d '\n' | xxd -plain | sed 's/\(..\)/%\1/g' # echo '手机' |tr -d '\n' |od ...
- C++操作oracle数据库
数据库操作方式:可以采用ADO方式,也可以采用oracle本身提供的Proc*C/C++或者是OCCI方式操作数据库. 连接方式:可以是客户端连接.也可以是服务器端连接. 数据库配置:无论是何种连 ...
- Haskell语言学习笔记(82)Extensible effects
安装 extensible-effects $ cabal install extensible-effects Installed extensible-effects-3.0.0.0 Extens ...
- linux shell 语法学习
文件比较运算符-e filename 如果 filename存在,则为真 [ -e /var/log/syslog ]-d filename 如果 filename为目录,则为真 [ -d /tmp/ ...
- scala case类
case类 case class Person(name:String) case 类有如下特点: 1. 构造参数默认是 val 的. 2. case 类实例化对象的时候,不需要 new 关键字.因为 ...
- mysql 回顾
主键可以是一个或者是多个列,但所有的列(或者是列的组合)必须是唯一的,非空的 关键字distinct 可以去重,实现该效果还可以使用group by limit 默认从 0 开始,limit 5 其实 ...
- springboot 整合redis redis工具类
一步 : pom中引入相关依赖 <!-- 引入 redis 依赖 --> <dependency> <groupId>org.springframework.boo ...
- easyUi 表头排序按钮 bug
参考文章:https://www.shiqidu.com/p/81
- C++ 将数据转为字符串的几种方法
收集一下: 1\将int 转为 LPCTSTR 其实LPCTSTR可以直接使用CString直接代替,无需类型强制转换 CString str; ; //str="15" str. ...