android - 如何在 android 中将 Path (android.graphics.Path) 与 Canvas 一起使用?

标签 android android-custom-view

我正在开发实现 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/

相关文章:

java - 同步适配器未运行

Android:转换为 dalvik 格式失败,出现错误 1 ​​ADT 2.1

java - 通过在自定义 View 的 onDraw 中设置单位矩阵来抵消 Canvas

android - Canvas 不在自定义 View 中绘制

java - XmlPullParser - 解析嵌套标记

安卓运行时异常 :requestFeature() must be called before adding content in DialogFragment

java - 如何使用 DOM 检查返回的服务器代码?

Android:使 ListView 顶部的 View 与 ListView 一起滚动

android - 使1个自定义 View 失效导致 View 组中所有自定义 View 失效?

android - 画一个以捏为中心的圆