-1
我一直在試圖繪製一個圓弧頂部填充顏色的圓弧,並刪除customview矩形中圓弧的底部部分。我經歷了很多stackoverflow問題,但它不起作用。畫布中的白色區域需要從下面的截圖中移除。這裏顯示了customview的代碼。請幫我解決這個問題。由於如何從正方形customview android中刪除部分畫布?
代碼:
@Override
protected void onDraw(Canvas canvas) {
float size = Math.min(getWidth(), getWidth());
RectF rectRectF = new RectF(0, 0, getWidth(), getHeight());
Path rectPath = new Path();
rectPath.addRect(rectRectF, Path.Direction.CCW);
Paint bgPaint = new Paint();
bgPaint.setColor(Color.RED);
canvas.drawPath(rectPath, bgPaint);
RectF rectF = new RectF(0, 0, 2 * getWidth(), 2 * getWidth());
Paint transparentPaint = new Paint();
transparentPaint.setColor(Color.WHITE);
transparentPaint.setAntiAlias(true);
canvas.drawArc(rectF, 180, 90, true, transparentPaint);
}
我已經使用過這段代碼,但是當我設置矩形畫布的背景顏色時,這段代碼給出了圓弧的透明bg。但背景顏色來到前景,我不想在畫布上做 –