我有一個擴展視圖類類MyView的。 MyView應繪製實心三角形。我畫了一個三角形,但我無法填充它。這是我的onDraw()方法:如何畫實心三角Android上的帆布
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Paint paint = new Paint();
paint.setColor(android.graphics.Color.BLACK);
canvas.drawPaint(paint);
paint.setStrokeWidth(4);
paint.setColor(android.graphics.Color.RED);
paint.setStyle(Paint.Style.FILL_AND_STROKE);
paint.setAntiAlias(true);
Point a = new Point(0, 0);
Point b = new Point(0, 100);
Point c = new Point(87, 50);
Path path = new Path();
path.setFillType(FillType.EVEN_ODD);
path.moveTo(a.x, a.y);
path.lineTo(b.x, b.y);
path.moveTo(b.x, b.y);
path.lineTo(c.x, c.y);
path.moveTo(c.x, c.y);
path.lineTo(a.x, a.y);
path.close();
canvas.drawPath(path, paint);
}
這是我得到的結果:
第一了lineTo應的moveTo。否則,它將從點(0,0)開始繪製。在這種情況下不是問題,但是因爲我想從中心抽籤,所以我面臨這個問題。 – lucasjmatias