android canvas.drawArc方法介绍

方法声明如下:
    /**
     * <p>Draw the specified arc, which will be scaled to fit inside the
     * specified oval.</p>
     * 
     * <p>If the start angle is negative or >= 360, the start angle is treated
     * as start angle modulo 360.</p>
     * 
     * <p>If the sweep angle is >= 360, then the oval is drawn
     * completely. Note that this differs slightly from SkPath::arcTo, which
     * treats the sweep angle modulo 360. If the sweep angle is negative,
     * the sweep angle is treated as sweep angle modulo 360</p>
     * 
     * <p>The arc is drawn clockwise. An angle of 0 degrees correspond to the
     * geometric angle of 0 degrees (3 o'clock on a watch.)</p>
     *
     * @param oval       The bounds of oval used to define the shape and size
     *                   of the arc
     * @param startAngle Starting angle (in degrees) where the arc begins
     * @param sweepAngle Sweep angle (in degrees) measured clockwise
     * @param useCenter If true, include the center of the oval in the arc, and
                        close it if it is being stroked. This will draw a wedge
     * @param paint      The paint used to draw the arc
     */
    public void drawArc(RectF oval, float startAngle, float sweepAngle, boolean useCenter, Paint paint)
      


其中oval为圆弧的矩形区域,画出来的圆弧是以这个矩形的内切圆的一部份;startAngle所画弧的开始角度,顺时针为正,逆时针为负;sweepAngle 旋转角度,即以startAngle的起点的旋转角度,顺时针为正,逆时针为负;useCenter是否闭合弧的起始点和终止点的;paint为画笔

RectF说明:

    /**
     * Create a new rectangle with the specified coordinates. Note: no range
     * checking is performed, so the caller must ensure that left <= right and
     * top <= bottom.
     *
     * @param left   The X coordinate of the left side of the rectangle
     * @param top    The Y coordinate of the top of the rectangle
     * @param right  The X coordinate of the right side of the rectangle
     * @param bottom The Y coordinate of the bottom of the rectangle
     */
    public RectF(float left, float top, float right, float bottom)

 其中参数left为矩形左边点的X坐标,right为右边点的X坐标,top上矩形上边的y坐标,bottom为矩形下边的y坐标,其中右边X坐标应该大于左边的X坐标,下边的Y坐标应该大于上边的Y坐标;

drawArc和drawRect的使用效果范例:

			Paint paint2 = new Paint();
			paint2.setColor(Color.RED);
			
			RectF rectF = new RectF();
			rectF.left =30;
			rectF.top = 190;
			rectF.right = 120;
			rectF.bottom = 280;
			canvas.drawRect(rectF, paint2);
			
			rectF.left =160;
			rectF.top = 190;
			rectF.right = 250;
			rectF.bottom = 280;
			canvas.drawArc(rectF, 30, -270, true, paint2);



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值