【问题标题】:How to use Path (android.graphics.Path) with canvas in android?如何在 android 中将 Path (android.graphics.Path) 与画布一起使用?
【发布时间】:2013-03-24 10:34:43
【问题描述】:

我正在开发一个实现 Catch 应用程序(如循环菜单)的自定义视图。花了很多时间后,我有了一点进步,完成了多种颜色的外半圆。现在,在阅读 Catch 应用程序的开发人员为用户提供的查询的答案时,我遇到了类 Path。 Google Android 开发者页面没有提供足够的材料来理解和熟悉 Path。所以,请 ?有人吗?

提前致谢。

【问题讨论】:

    标签: android android-custom-view


    【解决方案1】:

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

    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

    【讨论】:

    • 来自文档:向路径添加一个闭合的圆形轮廓。例如在“I”上方绘制点。
    • 我想将该 pathData 绘制到画布上,如果单个矢量有多个 pathData 我想将每个 pathData 一个一个地绘制到画布上,因为我想在单击时允许拖动/飞行每个 pathdata。该怎么做,你能帮帮我吗?
    猜你喜欢
    • 1970-01-01
    • 2014-01-15
    • 2011-08-06
    • 2013-11-14
    • 1970-01-01
    • 2014-02-20
    • 2012-06-20
    • 2012-01-17
    • 2020-09-07
    相关资源
    最近更新 更多