我正在學習Android,並嘗試在畫布上繪製不同的形狀。目前,我堅持用不同的角度橢圓:如何在Android中繪製形狀
我試着使用path.addRoundRect()
方法(其中一個需要半徑的陣列),但無法弄清楚怎樣設定我通過那裏以達到這樣的形狀。我也嘗試過使用path.lineTo()
,但無法達到這樣的效果(這有點類似,但仍然不是我所需要的)。什麼會是一個很好的解決方案來完成這個?
編輯1:我曾嘗試爲以下幾點:
Path path= new Path();
path.moveTo(x - radius, y - radius/ 1.5f);
path.lineTo(x - radius/ 4, y - radius);
path.lineTo(x, y - radius);
path.lineTo(x + radius/ 2, y - radius);
path.lineTo(x + radius, y - radius/ 2);
path.lineTo(x, y + radius/ 2);
path.lineTo(x - radius/ 2, y + radius/ 1.5f);
path.lineTo(x - radius, y + radius/ 4);
path.lineTo(x - radius, y - radius/ 1.5f);
path.close();
Paint pathPaint = new Paint();
pathPaint.setColor(Color.BLACK);
pathPaint.setStrokeWidth(2.5f);
pathPaint.setDither(true);
pathPaint.setStyle(Style.STROKE);
pathPaint.setStrokeJoin(Join.ROUND);
pathPaint.setStrokeCap(Cap.ROUND);
pathPaint.setPathEffect(new CornerPathEffect(20));
pathPaint.setAntiAlias(true);
canvas.drawOval(new RectF(x - radius, y - radius+ 2, x + radius-2, y + radius- 2), pathPaint);
canvas.drawPath(path, pathPaint);
X和Y是顯示器和半徑上的一些座標是圓的半徑(我開始用圓圈繪製)。它等於14 px。
我也試着這樣說:
float[] radii = new float[] {
5,
5,
1,
1,
5,
1,
1,
1,
};
path.addRoundRect(new RectF(x - radius, y - radius, x + radius,
y + radius),
radii, Direction.CW);
canvas.drawPath(path, pathPaint);
你可以發佈你的代碼嗎? – petey 2013-04-26 17:53:58
http://developer.android.com/reference/android/graphics/drawable/shapes/OvalShape.html – 2013-04-26 17:55:18