赞
踩
在开发中,需要用到弧形进度条,上网上查了下,有个开源的绘制弧形进度条的,只是它的渐变颜色是分成四段,不是很美观,于是自己参考着做了一个,效果如下图:
这个进度条控件我是参考Radial-Menu-Widget-Android-master开源代码的RadialProgressActivity.java文件改的,修改的主要是它的onDraw函数,修改如下:
- protected void onDraw(Canvas canvas) {
- super.onDraw(canvas);
- this.mRadialWidgetPaint.setStyle(Paint.Style.FILL);
- this.mRadialWidgetPaint.setColor(this.mBorderColor);
- /*用底色画一个圆环,带间隔效果*/
- for(int i = 0; i < this.mMaxSweepAngle; i+=10){
- canvas.drawArc(this.mRadialScoreRect, 90.0F+i, 9.9F, true, this.mRadialWidgetPaint);
- }
-
- if(this.mCurrentValue <= this.mMaxValue) {
- double textWidth = (double)(this.mCurrentValue * this.mMaxSweepAngle / this.mMaxValue);
- this.readingValuePer = this.mCurrentValue * 100 / this.mMaxValue;
-
- int i = 0;
- float rate = 0;
- float startAngle = 90.0F;
- /*根据进度条的长度分成长度为10的若干段,每段通过设置alpha值调节颜色*/
- for(i = 0; i<=textWidth-10; i+=10){
- rate = (float)(Math.abs(180-i)/180.0);
- this.mCurrentScoreColor = ((int)(0XFF*rate) <<24)|(this.mScoreColorRange[0] & (~(0XFF <<
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。