绘制模拟Android钟 ####时钟表盘

protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        //绘制时钟的外圈,
        circlePaint.setColor(circleColor01);
        canvas.drawCircle(this.getWidth() / 2, this.getHeight() / 2,
                this.getWidth() / 2, circlePaint);
        circlePaint.setColor(circleColor02);
        canvas.drawCircle(this.getWidth() / 2, this.getHeight() / 2,
                this.getWidth() / 2 - circleWidth, circlePaint);

        //绘制时钟的表盘
        canvas.save();
        for (int i=0;i<12;i++) {
            canvas.drawLine(this.getWidth()/2,20*density,
                    this.getWidth()/2,circleWidth + 1*density,linePaint);
            canvas.rotate(30,this.getWidth()/2,this.getHeight()/2);
        }
        canvas.restore();
        //刻度值数字

        //绘制小时,分钟和秒数针
        canvas.save();
        canvas.rotate(hour * 30 + minute / 2, this.getWidth() / 2, this.getHeight() / 2);
        timerPaint.setStrokeWidth(5.0f * density);
        canvas.drawLine(this.getWidth() / 2, this.getHeight() / 2, this.getWidth() / 2,
                circleWidth + (this.getHeight() / 5) * density, timerPaint);
        canvas.restore();

        canvas.save();
        canvas.rotate(minute * 6, this.getWidth() / 2, this.getHeight() / 2);
        timerPaint.setStrokeWidth(4.0f * density);
        canvas.drawLine(this.getWidth() / 2, this.getHeight() / 2,
                this.getWidth() / 2, circleWidth + (this.getHeight() / 7) * density, timerPaint);
        canvas.restore();

        canvas.save();
        canvas.rotate(second * 6,this.getWidth()/2,this.getHeight()/2);
        timerPaint.setStrokeWidth(3.0f*density);
        canvas.drawLine(this.getWidth()/2,this.getHeight()/2,
                this.getWidth()/2,circleWidth+(this.getHeight()/9)*density,timerPaint);
        canvas.restore();
    }


<img src="https://img-blog.csdn.net/20160315232136063?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="" />

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值