如何在android中使用带有canvas的Path(android.graphics.Path)?

时间:2013-03-24 10:34:44

标签: android android-custom-view

我正在开发一个自定义视图,它实现了像圆形菜单这样的Catch应用程序。花了很多时间后,我取得了一些进步,完成了多色的外半圆。现在,阅读Catch应用程序的开发人员为他的查询提供的答案,我遇到了类Path。 Google Android Developer页面没有提供足够的材料来理解和熟悉Path。所以,请 ?任何人?

提前致谢。

1 个答案:

答案 0 :(得分:24)

您可以使用它在画布上绘制线条。路径基本上是行的集合。您可以使用它来创建非标准的形状。例如。有很多函数可以创建一些默认形状:

canvas.drawRect();
canvas.drawArc(RectF oval, float startAngle, float sweepAngle, boolean useCenter, Paint paint);
canvas.drawCircle(float cx, float cy, float radius, Paint paint);
canvas.drawLine(float startX, float startY, float stopX, float stopY, Paint paint);
canvas.drawOval(RectF oval, Paint paint);
canvas.drawRect(float left, float top, float right, float bottom, Paint paint);

但是如果你想要一些自定义的东西,你可以创建一个路径,并通过调用

// Set the beginning of the next contour to the point (x,y).
void     moveTo(float x, float y)

// Add a line from the last point to the specified point (x,y).
void     lineTo(float x, float y)

您可以控制绘制路径线条的铅笔。 Here's a nice tutorial