问题
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