android自定义控件颜色渐变,自定义控件之圆形颜色渐变进度条--SweepGradient

packagecom.soyoungboy.sweepgradientprogress;importandroid.content.Context;importandroid.graphics.BlurMaskFilter;importandroid.graphics.Canvas;importandroid.graphics.Color;importandroid.graphics.EmbossMaskFilter;importandroid.graphics.Paint;importandroid.graphics.RectF;importandroid.util.AttributeSet;importandroid.view.View;/*** 圆形颜色渐变的进度条

*@authorsoyoungboy

**/

public class SweepGradientCircleProgressBar extendsView {privatePaint pathPaint;privatePaint fillArcPaint;//设置光源的方向

private float[] direction = new float[] {1, 1, 1};//设置环境光亮度

private float light = 0.4f;//选择要应用的反射等级

private float specular = 6;privateEmbossMaskFilter emboss;privateRectF oval ;privateBlurMaskFilter mBlur;//view重绘的标记

private boolean reset = false;//向 mask应用一定级别的模糊

private float blur = 3.5f;private int arcradus = 30;publicSweepGradientCircleProgressBar(Context context ,AttributeSet attrs) {super(context,attrs);

initPaint();

oval= newRectF();

emboss= newEmbossMaskFilter(direction, light, specular, blur);

mBlur= new BlurMaskFilter(20, BlurMaskFilter.Blur.NORMAL);

}//初始化画笔操作

private voidinitPaint() {//初始化画笔操作

pathPaint = newPaint();//设置是否抗锯齿

pathPaint.setAntiAlias(true);//帮助消除锯齿

pathPaint.setFlags(Paint.ANTI_ALIAS_FLAG);//设置中空的样式

pathPaint.setStyle(Paint.Style.STROKE);

pathPaint.setDither(true);

pathPaint.setStrokeJoin(Paint.Join.ROUND);

fillArcPaint= newPaint();//设置是否抗锯齿

fillArcPaint.setAntiAlias(true);//帮助消除锯齿

fillArcPaint.setFlags(Paint.ANTI_ALIAS_FLAG);//设置中空的样式

fillArcPaint.setStyle(Paint.Style.STROKE);

fillArcPaint.setDither(true);

fillArcPaint.setStrokeJoin(Paint.Join.ROUND);

}

@Overrideprotected voidonDraw(Canvas canvas) {super.onDraw(canvas);int height =getMeasuredWidth();int width =getMeasuredWidth();//半径 = 宽/2-圆环的宽度

int radius = width/2-arcradus;int cx = width/2;int cy = height/2;//绘制画笔颜色

pathPaint.setColor(Color.RED);//画笔的宽度

pathPaint.setStrokeWidth(10);

pathPaint.setMaskFilter(emboss);

canvas.drawCircle(cx, cy, radius, pathPaint);

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值