码迷,mamicode.com
首页 > 其他好文 > 详细

关于canvas.drawArc,canvas.drawOval 和RectF 的关系

时间:2015-03-13 14:22:06      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:view

1.paint.setStyle(Paint.Style.STROKE)

//    radius="100dp"
//    interRadius="40dp"
//    linearWidth="10dp"
//    stokenWidth="40dp"


        mPaint=new Paint();
        mPaint.setStyle(Paint.Style.STROKE);
        mPaint.setStrokeWidth(mStokenWidth);
        mPaint.setColor(Color.BLUE);
        mPaint.setAntiAlias(true);

        mPaint2=new Paint();
        mPaint2.setStyle(Paint.Style.STROKE);
        mPaint2.setColor(Color.BLACK);

        int left=mStokenWidth/2;
        int top=mStokenWidth/2;
        mRectF=new RectF();
        mRectF.left=left;
        mRectF.top=top;
        mRectF.right=(mRadius-left)*2;
        mRectF.bottom=(mRadius-top)*2;

onDraw

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.drawArc(mRectF, 0, 90, false, mPaint);
        mPaint.setColor(Color.RED);
        canvas.drawArc(mRectF, 90, 90, false, mPaint);
        mPaint.setColor(Color.YELLOW);
        canvas.drawArc(mRectF, 180, 90, false, mPaint);
        mPaint.setColor(Color.GRAY);
        canvas.drawArc(mRectF, 270, 90, false, mPaint);
        canvas.drawRect(mRectF,mPaint2);
    }


如图:技术分享


2.paint.setStyle(Paint.Style.FILL)

效果如下

技术分享

RectF画的矩形刚好成为了扇形的外切矩形

说明当style 为stoken 的时候,rectf画出的举行每条边刚好在描边的中间

当style为Fill的时候,rect为整个图形的外切矩形

关于canvas.drawArc,canvas.drawOval 和RectF 的关系

标签:view

原文地址:http://blog.csdn.net/senyangs/article/details/44240307

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!