方法声明如下:
其中参数left为矩形左边点的X坐标,right为右边点的X坐标,top上矩形上边的y坐标,bottom为矩形下边的y坐标,其中右边X坐标应该大于左边的X坐标,下边的Y坐标应该大于上边的Y坐标;
/**
* <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);