Android ApiDemos example (53): Graphics-& gt; Arcs

Source: Internet
Author: User
Tags in degrees

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
 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.