How to use Path (android.graphics.Path) with canvas in android?

拟墨画扇 提交于 2019-12-12 07:45:14

问题


I am working on a Custom View that implements Catch application like Circular Menu. After spending a lot of time, I have made a bit of progress, completed outer semi-circle with multile colors. Now, reading an answer provided by developer of Catch application to an user for his query, I came across the class Path. Google Android Developer page does not provides enough material to be understood and to be familiar with Path. so, Please ? Anyone ?

Thanks in advance.


回答1:


You can use it to draw lines on a canvas. A path is basically a collection of lines. You can use it to create shapes that are not standard. E.g. there a lots of functions to create some default shapes:

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);

But if you want something custom, you can create a path, and by calling

// 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)

You have control of the pencil that draws the lines of your path. Here's a nice tutorial



来源:https://stackoverflow.com/questions/15597411/how-to-use-path-android-graphics-path-with-canvas-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!