正如你已經發現了,我會用夾子:
我會用
Canvas.clipPath()
路徑看起來像餡餅sl冰開始在圓圈的中心,就像這樣:
要創建剪輯路徑類似:
public class PieView extends View {
private int width = 200;
private int angleStart = 135;
private int sweep = 270;
private Path p;
private Paint paint = new Paint();
public PieView(Context context, AttributeSet attrs) {
super(context, attrs);
p = new Path();
//move into center of the circle
p.setLastPoint(width/2, width/2);
//add line from the center to arc at specified angle
p.lineTo(width/2+(float)Math.cos(Math.toRadians(angleStart))*(width/2),
width/2+(float)Math.sin(Math.toRadians(angleStart))*(width/2));
//add arc from start angle with specified sweep
p.addArc(new RectF(0, 0, width, width), angleStart, sweep);
//from end of arc return to the center of circle
p.lineTo(width/2, width/2);
paint.setColor(Color.RED);
paint.setStrokeWidth(1);
paint.setStyle(Style.STROKE);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawRect(0,0,width,width, paint);
canvas.drawPath(p,paint);
}
}
好吧,我會給你一個鏡頭。我如何讓它看起來動畫?像它被填滿? – 2011-05-27 19:41:34
執行一些循環並相應地更改裁減 – Ludevik 2011-05-27 20:00:52
我對裁剪部分有點困惑。好的,所以有一個矩形是矩形所在尺寸的邊界框: RectF bounds = new RectF(0,0,200,200); 我想做一個clip.addArc(bouns,起始角度,掃描角度);即時假設,我的開始和掃描角度是什麼?我嘗試了180到0,但似乎並沒有產生正確的圖像。 – 2011-05-27 20:22:34