1、 新建画笔
paintCircle =new Paint();
paintCircle.setColor(Color.RED);
paintCircle.setStrokeWidth(mClockRingWidth);
paintCircle.setAntiAlias(true);
paintCircle.setStyle(Paint.Style.STROKE);
//中心圆点
paintPoint =new Paint();
paintPoint.setStyle(Paint.Style.STROKE);
paintPoint.setAntiAlias(true);
paintPoint.setStrokeWidth(10);
paintPoint.setColor(Color.RED);
//指针
paintPointer =new Paint();
paintPointer.setStyle(Paint.Style.FILL_AND_STROKE);
paintPointer.setAntiAlias(true);
paintPointer.setStrokeCap(Paint.Cap.ROUND);
//数字
paintNum =new Paint();
paintNum.setStyle(Paint.Style.FILL_AND_STROKE);
paintNum.setAntiAlias(true);
paintNum.setTextSize(28);
paintNum.setColor(Color.BLACK);
paintNum.setStrokeCap(Paint.Cap.ROUND);
2、重写onDraw()
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
确定画布中心位置
canvas.translate(mCenterX,mCenterY);
drawCircle(canvas);
drawPoint(canvas);
drawNum(canvas);
drawPointer(canvas);
}
3、画时钟外圆及刻度
4、画 圆心
canvas.drawCircle(0,0,mClockRingWidth,paintPoint);
5、画指针
6、画 数字
7、例图
8、让指针走动
开启定时器,调用postInvalidate()
网友评论