自定义进度条渐变色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 ...
随机推荐
- tips___代码规范
函数变量尽可能置于最小作用域内,并在变量声明时进行初始化 变量声明的位置最好离第一次使用的位置越近越好:应使用初始化的方式代替声明再赋值. int x=0; rather than int x; x ...
- Servlet基本_画面遷移
画面遷移方法は.下記ようがある.・リクエストのディスパッチ・リダイレクト(画面から) 1.ディスパッチ1)概念サーブレットから他のリソース(サーブレット.JSP.Htmlなど)にリクエストを転送するこ ...
- DO and DOES Reduction
DO and DOES Reduction Share Tweet Share Tagged With: DO and DOES Reductions ‘Do’ and ‘does’ can be r ...
- linux下mysql开启远程访问权限 防火墙开放3306端口
linux下mysql开启远程访问权限 防火墙开放3306端口 转载 2017-01-21 作者:JAVA-ANDROID 这篇文章主要为大家详细介绍了linux下mysql开启远程访问权限,防 ...
- jquery实现分页+单删批删
//定义一个分页的方法 public function fenye(){ //查询满足条件的总条数 $count = M("regis")->count(); //设置每页显 ...
- Android Studio 3.0.1 又见恶心爆的bug。。。xiete
写了个AIDL的东西,结果一直编译不通过: Error:Execution failed for task ':app:compileDebugAidl'. > java.io.IOExcept ...
- 13.BeanUtils组件-基础.md
目录 用途 基本属性的设置 Map数据的拷贝 对象的拷贝 转换器 用途 可以用来对JavaBean的各种增强操作 基本属性的设置 package per.liyue.code.beanutildemo ...
- Ajax 学习 第一篇
http请求: 1.请求的方法或动作 2.正在请求的url 3.请求头 4.请求体 及请求正文 典型例子 get.post区别 1.get 幂等 执行一次哪怕一万次影响相同 一般用于信息获取 ...
- PowerDesigner 修改table背景色
Tools->Display Preferences(显示参数选择)->Format->Table->Modify->Fill->Fill color 出处:htt ...
- 实例的render方法渲染组件
1.普通渲染组件 在app容器中插入login组件 <login></login> 一个app可以多个这种组件 <script> var login = { te ...