我必須繪製一個由圓形內的三角形組成的自定義shapeDrawable。我可以繪製圓和三角形的問題是,我想三角形是透明的,但是當我給一個三角形的路徑透明的顏色,我會看到圓的顏色insde三角形我想沒有顏色作爲三角背景的圓? 這裏是我使用的代碼:透明三角形裏面一個圓圈我如何覆蓋圓形的顏色
@Override
protected void onDraw(Canvas canvas) {
Paint p = new Paint();
int x = 1;
int y = 1;
Rect bounds = canvas.getClipBounds();
p.setColor (color.getBackgroundColor());
p.setStyle(Style.FILL);
p.setStrokeWidth (0);
Path path = new Path();
Point p1 = new Point(bounds.centerX()-bounds.height()/4, bounds.centerY()-bounds.height()/4);
Point p2 = new Point(bounds.centerX()-bounds.height()/4, bounds.centerY()+bounds.height()/4);
Point p3 = new Point(bounds.centerX()+bounds.height()/4, bounds.centerY());
path.moveTo(p1.x, p1.y);
path.lineTo(p2.x, p2.y);
path.lineTo(p3.x, p3.y);
path.close();
Paint pTriang = new Paint();
pTriang.setColor(Color.TRANSPARENT);
pTriang.setXfermode(new PorterDuffXfermode(android.graphics.PorterDuff.Mode.CLEAR));
canvas.drawCircle(bounds.exactCenterX(), bounds.exactCenterY(), bounds.height()/2, p);
canvas.drawPath(path, pTriang);
}
BTW我正在重寫的ImageView的!
看在http://stackoverflow.com/questions/3874424/android-looking-for-a-drawarc-method-with-inner-outer-radius – ngesh 2013-04-04 14:47:58
:在你的構造函數的末尾添加這這個問題,他們沒有給出任何解決方案,因爲我已經使用Xfermode,但我不能有我想要的東西 – 2013-04-04 15:05:58