Android自定义view(圆形进度条)
来源:互联网 发布:2015旅游数据 编辑:程序博客网 时间:2024/04/30 21:04
public class MyRoundProgressBar extends View { private Paint paint; float x, y; CircleStyle cs; private int rout; private float radius; public MyRoundProgressBar(Context context) { super(context); init(); } public MyRoundProgressBar(Context context, @Nullable AttributeSet attrs) { super(context, attrs); init(); } public MyRoundProgressBar(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); init(); } public void init() { paint = new Paint(); paint.setAntiAlias(true); rout = 0; radius = 100; } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (cs == null) { cs = new CircleStyle(radius, Color.BLACK, rout); x = getWidth() / 2; y = getHeight() / 2; paint.setColor(Color.BLACK); //消除锯齿 paint.setStyle(Paint.Style.STROKE); //设置粗细 paint.setStrokeWidth(1); canvas.drawCircle(x, y, cs.getRadiu() - 10, paint); canvas.drawCircle(x, y, cs.getRadiu() + 10, paint); paint.setColor(cs.getColor()); //设置粗细 paint.setStrokeWidth(18); RectF rect = new RectF(); //进行画圆弧 rect.set(x - cs.getRadiu(), y - cs.getRadiu(), x + cs.getRadiu(), y + cs.getRadiu()); canvas.drawArc(rect, 0.0f, cs.getRound(), false, paint); startAnimation(); } else { paint.setColor(Color.BLACK); //设置圆环的颜色 paint.setStyle(Paint.Style.STROKE); paint.setStrokeWidth(1); canvas.drawCircle(x, y, cs.getRadiu() - 10, paint); canvas.drawCircle(x, y, cs.getRadiu() + 10, paint); paint.setColor(cs.getColor()); paint.setStrokeWidth(18); RectF rect = new RectF(); rect.set(x - cs.getRadiu(), y - cs.getRadiu(), x + cs.getRadiu(), y + cs.getRadiu()); canvas.drawArc(rect, 0.0f, cs.getRound(), false, paint); } } private void startAnimation() { ValueAnimator animator = ValueAnimator.ofObject(new CircleEvaluator(), new CircleStyle(radius, Color.BLACK, 0), new CircleStyle(radius, Color.BLACK, 360)); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { cs = (CircleStyle) animation.getAnimatedValue(); invalidate(); } }); animator.setDuration(10000); animator.start(); } class CircleEvaluator implements TypeEvaluator { @Override public Object evaluate(float fraction, Object startValue, Object endValue) { CircleStyle start = (CircleStyle) startValue; CircleStyle end = (CircleStyle) endValue; float round = start.getRound() + fraction * (end.getRound() - start.getRound()); int colorR = Math.abs((int) (216 - fraction * (245 - 16))); int colorG = Math.abs((int) (156 - fraction * (45 - 16))); int colorB = Math.abs((int) (24 - fraction * (234 - 16))); //三原色的设置 String tempR = Integer.toHexString(colorR); String tempG = Integer.toHexString(colorG); String tempB = Integer.toHexString(colorB); if (tempR.length() < 2) { tempR += "0"; } if (tempG.length() < 2) { tempG += "0"; } if (tempB.length() < 2) { tempB += "0"; } String tempColor = "#" + tempR + tempG + tempB;//#fff3a3 System.out.println("---" + tempColor); int color = Color.parseColor(tempColor); CircleStyle cs = new CircleStyle(radius, color, round); return cs; } } class CircleStyle { float radiu; int color; float round; public CircleStyle(float radiu, int color, float round) { this.radiu = radiu; this.color = color; this.round = round; } public float getRadiu() { return radiu; } public void setRadiu(float radiu) { this.radiu = radiu; } public int getColor() { return color; } public void setColor(int color) { this.color = color; } public float getRound() { return round; } public void setRound(float round) { this.round = round; } }}
阅读全文
0 0
- android 圆形进度条 自定义view
- android 自定义view 圆形进度条
- Android自定义View---圆形进度条
- Android-------自定义View圆形进度条
- Android自定义view(圆形进度条)
- Android自定义view圆形进度条
- Android自定义view圆形进度条
- Android自定义View-圆形进度条
- 自定义View实现Android圆形进度条
- Android 自定义view --圆形百分比(进度条)
- Android 自定义圆形进度条(圆环刻度)View
- Android自定义View之圆形进度条
- Android 自定义view --圆形百分比(进度条)
- Android自定义View--圆形进度条RoundProgress
- 【Android自定义view系列】圆形百分比进度条
- Android-自定义View之圆形进度条总结
- Android 自定义 View 圆形进度条总结
- Android 自定义 View 圆形进度条总结
- spring AOP
- [MYSQL-5]排序检索数据
- --致橡树--
- poj1410(计算几何)
- R8 STM32 SPI—读写串行 FLASH
- Android自定义view(圆形进度条)
- Tallest Cow POJ
- 【modelsim和debussy】设置
- 云盘开发利器elfinder
- syslog-ng详解——运行syslog-ng
- #大二上数据结构#输出全部子集
- rabbitma编译为乱码 与 解决RabbitMQ service is already present
- 装饰与函数
- 利用C++将输入一个字符串把其中的字符串逆向输出