Canvas provides drawArc to draw an arc.
Public void drawArc (RectF oval, float startAngle, float sweepAngle, boolean useCenter, Paint)
Oval: Specifies the rectangular area of the outer contour of the arc.
StartAngle: the starting angle of the arc, measured in degrees.
SweepAngle: the angle of the arc scanning. It is clockwise and measured in degrees.
UseCenter: if it is True, the center of the circle is included when the arc is drawn, which is usually used to draw slices.
Paint: Specifies the drawing board attribute of an arc, such as color or fill.
This example demonstrates four different usage methods of drawArc,
1. Fill in the arc but do not include the center of the circle:
[Java]
MPaints [0] = new Paint ();
MPaints [0]. setAntiAlias (true );
MPaints [0]. setStyle (Paint. Style. FILL );
MPaints [0]. setColor (0x88FF0000 );
MUseCenters [0] = false;
MPaints [0] = new Paint ();
MPaints [0]. setAntiAlias (true );
MPaints [0]. setStyle (Paint. Style. FILL );
MPaints [0]. setColor (0x88FF0000 );
MUseCenters [0] = false;
2. Fill in the arc with the center (slice)
[Java]
MPaints [1] = new Paint (mPaints [0]);
MPaints [1]. setColor (0x8800FF00 );
MUseCenters [1] = true;
MPaints [1] = new Paint (mPaints [0]);
MPaints [1]. setColor (0x8800FF00 );
MUseCenters [1] = true;
3. Draw only the circumference, excluding the center of the circle
[Java]
MPaints [3] = new Paint (mPaints [2]);
MPaints [3]. setColor (0x88888888 );
MUseCenters [3] = true;
MPaints [3] = new Paint (mPaints [2]);
MPaints [3]. setColor (0x88888888 );
MUseCenters [3] = true;
4. Draw only the circumference with the center (slice)
[Java]
MPaints [3] = new Paint (mPaints [2]);
MPaints [3]. setColor (0x88888888 );
MUseCenters [3] = true;
MPaints [3] = new Paint (mPaints [2]);
MPaints [3]. setColor (0x88888888 );
MUseCenters [3] = true;
In this example, onDraw
[Java]
Protected void onDraw (Canvas canvas ){
Canvas. drawColor (Color. WHITE );
DrawArcs (canvas, mBigOval, mUseCenters [mBigIndex],
MPaints [mBigIndex]);
For (int I = 0; I <4; I ++ ){
DrawArcs (canvas, mOvals [I], mUseCenters [I], mPaints [I]);
}
MSweep + = SWEEP_INC;
If (mSweep & gt; 360 ){
MSweep-= 360;
MStart + = START_INC;
If (mStart> = 360 ){
MStart-= 360;
}
MBigIndex = (mBigIndex + 1) % mOvals. length;
}
Invalidate ();
}
Protected void onDraw (Canvas canvas ){
Canvas. drawColor (Color. WHITE );
DrawArcs (canvas, mBigOval, mUseCenters [mBigIndex],
MPaints [mBigIndex]);
For (int I = 0; I <4; I ++ ){
DrawArcs (canvas, mOvals [I], mUseCenters [I], mPaints [I]);
}
MSweep + = SWEEP_INC;
If (mSweep & gt; 360 ){
MSweep-= 360;
MStart + = START_INC;
If (mStart> = 360 ){
MStart-= 360;
}
MBigIndex = (mBigIndex + 1) % mOvals. length;
}
Invalidate ();
}
Similarly, when invalidate () is called in onDraw, onDraw will be triggered again, and the display will be refreshed continuously. startAngle and sweepAngle will start from cycle to form the animation effect. The top big image sequence will show the four usage of drawArc:
Paint. Style. STROKE indicates that only the outline of the image is currently drawn, while Paint. Style. FILL indicates the filling image.
Author: mapdigit