2011.07.18(3)——— android drawArc 画弧参考:[url]http://www.imobilebbs.com/wordpress/?p=1377[/url]
?
Canvas提供了drawArc来绘制圆弧。 public void drawArc(RectF oval, float startAngle, float sweepAngle, boolean useCenter, Paint paint) 本例演示了drawArc的四种不同用法, 1. 填充圆弧但不含圆心: 2. 填充圆弧带圆心(扇形) 3. 只绘圆周,不含圆心 4. 只绘圆周,带圆心(扇形) 本例的onDraw 同样onDraw之中调用invalidate(),会再触发onDraw,从而不停刷新显示,startAngle, sweepAngle周而复始,形成动画效果,最上的大图顺序显示drawArc的这四种用法: Paint.Style.STROKE 表示当前只绘制图形的轮廓,而Paint.Style.FILL表示填充图形。mPaints[
0
] =
new
Paint();
mPaints[
0
].setAntiAlias(
true
);
mPaints[
0
].setStyle(Paint.Style.FILL);
mPaints[
0
].setColor(
0x88FF0000
);
mUseCenters[
0
] =
false
;
mPaints[
1
] =
new
Paint(mPaints[
0
]);
mPaints[
1
].setColor(
0x8800FF00
);
mUseCenters[
1
] =
true
;
mPaints[
2
] =
new
Paint(mPaints[
0
]);
mPaints[
2
].setStyle(Paint.Style.STROKE);
mPaints[
2
].setStrokeWidth(
4
);
mPaints[
2
].setColor(
0x880000FF
);
mUseCenters[
2
] =
false
;
mPaints[
3
] =
new
Paint(mPaints[
2
]);
mPaints[
3
].setColor(
0x88888888
);
mUseCenters[
3
] =
true
;
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 >
360
) {
?
mSweep -=
360
;
?
mStart += START_INC;
?
if
(mStart >=
360
) {
?
mStart -=
360
;
?
}
?
mBigIndex = (mBigIndex +
1
) % mOvals.length;
?
}
?
invalidate();
?
}