我正在开发实现 Catch 应用程序(如循环菜单)的自定义 View 。花了很多时间后,我有了一点进步,完成了多种颜色的外半圆。现在,在阅读 Catch 应用程序的开发人员为用户提供的查询的答案时,我遇到了类 Path。 Google Android 开发者页面没有提供足够的 Material 来理解和熟悉 Path。所以,请 ?有人吗?
提前致谢。
最佳答案
您可以使用它在 Canvas 上绘制线条。路径基本上是线条的集合。您可以使用它来创建非标准的形状。例如。有很多函数可以创建一些默认形状:
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
关于android - 如何在 android 中将 Path (android.graphics.Path) 与 Canvas 一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15597411/