Paint wallpaint = new Paint(); wallpaint.setColor(Color.GRAY); wallpaint.setStyle(Style.FILL); Path wallpath = new Path(); wallpath.reset(); // only needed when reusing this path for a new build wallpath.moveTo(x[0], y[0]); // used for first point wallpath.lineTo(x[1], y[1]); wallpath.lineTo(x[2], y[2]); wallpath.lineTo(x[3], y[3]); wallpath.lineTo(x[0], y[0]); // there is a setLastPoint action but i found it not to work as expected canvas.drawPath(wallpath, wallpaint);
private Path getPathForSegment(float startAngle, float sweep) { Point center = new Point(getWidth() / 2, getHeight() / 2); RectF rect = new RectF(0f, 0f, getWidth(), getHeight()); Path selection = new Path(); selection.addArc(rect, startAngle, sweep); selection.lineTo(center.x, center.y); selection.close(); return selection; }
hexagonPath = new Path(); hexagonBorderPath = new Path(); maskColor = 0xFF01FF77; float centerX = width/2; float centerY = height/2; hexagonPath.moveTo(centerX, centerY + radius); hexagonPath.lineTo(centerX - triangleHeight, centerY + radius/2); hexagonPath.lineTo(centerX - triangleHeight, centerY - radius/2); hexagonPath.lineTo(centerX, centerY - radius); hexagonPath.lineTo(centerX + triangleHeight, centerY - radius/2); hexagonPath.lineTo(centerX + triangleHeight, centerY + radius/2); hexagonPath.moveTo(centerX, centerY + radius); hexagonBorderPath.moveTo(centerX, centerY + radiusBorder); hexagonBorderPath.lineTo(centerX - triangleBorderHeight, centerY + radiusBorder/2); hexagonBorderPath.lineTo(centerX - triangleBorderHeight, centerY - radiusBorder/2); hexagonBorderPath.lineTo(centerX, centerY - radiusBorder); hexagonBorderPath.lineTo(centerX + triangleBorderHeight, centerY - radiusBorder/2); hexagonBorderPath.lineTo(centerX + triangleBorderHeight, centerY + radiusBorder/2); hexagonBorderPath.moveTo(centerX, centerY + radiusBorder); invalidate();
canvas.drawRect(mIndicatorLeft, getHeight() - mSelectedIndicatorHeight - arrowSize, mIndicatorRight, getHeight() - arrowSize, mSelectedIndicatorPaint); canvas.drawPath(getTrianglePath(arrowSize), mSelectedIndicatorPaint); Point bottom = new Point(bottomPointX, bottomPointY); Path path = new Path(); path.setFillType(Path.FillType.EVEN_ODD); path.setLastPoint(left.x, left.y); path.lineTo(right.x, right.y); path.lineTo(bottom.x, bottom.y); path.lineTo(left.x, left.y); path.close();
// create and draw triangles // use a Path object to store the 3 line segments // use .offset to draw in many locations // note: this triangle is not centered at 0,0 paint.setStyle(Paint.Style.STROKE); paint.setStrokeWidth(2); paint.setColor(Color.RED); Path path = new Path(); path.moveTo(0, -10); path.lineTo(5, 0); path.lineTo(-5, 0); path.close(); path.offset(10, 40); canvas.drawPath(path, paint); path.offset(50, 100); canvas.drawPath(path, paint); // offset is cumlative // next draw displaces 50,100 from previous path.offset(50, 100); canvas.drawPath(path, paint);
protected void onDraw(Canvas canvas) { super.onDraw(canvas); int w = getWidth(); int h = getHeight(); Paint p = new Paint(Paint.ANTI_ALIAS_FLAG|Paint.FILTER_BITMAP_FLAG); Path pth = new Path(); pth.moveTo(w*0.27f,0); pth.lineTo(w*0.73f,0); pth.lineTo(w*0.92f,h); pth.lineTo(w*0.08f,h); pth.lineTo(w*0.27f,0); p.setColor(0xff800000); p.setShader(new LinearGradient(0,0,0,h,0xff000000,0xffffffff,Shader.TileMode.CLAMP)); canvas.drawPath(pth,p); }
final Path path = new Path(); final Paint paint = new Paint(); paint.setColor(Color.RED); paint.setAntiAlias(true); paint.setStyle(Paint.Style.FILL_AND_STROKE); path.moveTo(100, 100); path.lineTo(200, 100); path.lineTo(200, 200); path.lineTo(100, 200); path.close(); path.moveTo(150, 150); path.lineTo(180, 150); path.lineTo(180, 180); path.lineTo(150, 180); path.close(); path.setFillType(Path.FillType.EVEN_ODD); canvas.drawPath(path, paint);
public void onDraw(Canvas canvas) { Path path = new Path(); boolean first = true; for(int i = 0; i < points.size(); i += 2){ Point point = points.get(i); if(first){ first = false; path.moveTo(point.x, point.y); } else if(i < points.size() - 1){ Point next = points.get(i + 1); path.quadTo(point.x, point.y, next.x, next.y); } else{ path.lineTo(point.x, point.y); } } canvas.drawPath(path, paint); }
Path path = new Path(); if (points.size() > 1) { Point prevPoint = null; for (int i = 0; i < points.size(); i++) { Point point = points.get(i); if (i == 0) { path.moveTo(point.x, point.y); } else { float midX = (prevPoint.x + point.x) / 2; float midY = (prevPoint.y + point.y) / 2; if (i == 1) { path.lineTo(midX, midY); } else { path.quadTo(prevPoint.x, prevPoint.y, midX, midY); } } prevPoint = point; } path.lineTo(prevPoint.x, prevPoint.y); }
paint.setColor(android.graphics.Color.RED); paint.setStyle(Paint.Style.FILL_AND_STROKE); paint.setAntiAlias(true); mapView.getProjection().toPixels(point3, point3_draw); Path path = new Path(); path.setFillType(Path.FillType.EVEN_ODD); path.moveTo(point1_draw.x,point1_draw.y); path.lineTo(point2_draw.x,point2_draw.y); path.lineTo(point3_draw.x,point3_draw.y); path.lineTo(point1_draw.x,point1_draw.y); path.close();
Path fillPath = new Path(); fillPath.moveTo(0, 0); // Your origin point fillPath.lineTo(x1, y1); // First point // Repeat above line for all points on your line graph fillPath.lineTo(xN, yN); // Final point fillPath.lineTo(xN, 0); // Draw from final point to the axis ++ fillPath.lineTo(0, 0); // Same origin point yourCanvas.drawPath(fillPath, /* Your paint */);
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); Paint paint = new Paint(); paint.setColor(android.graphics.Color.BLACK); canvas.drawPaint(paint); paint.setStrokeWidth(4); paint.setColor(android.graphics.Color.RED); paint.setStyle(Paint.Style.FILL_AND_STROKE); paint.setAntiAlias(true); Point a = new Point(0, 0); Point b = new Point(0, 100); Point c = new Point(87, 50); Path path = new Path(); path.setFillType(FillType.EVEN_ODD); path.lineTo(b.x, b.y); path.lineTo(c.x, c.y); path.lineTo(a.x, a.y); path.close(); canvas.drawPath(path, paint); }
Path ctx = new Path(); ctx.moveTo(Ax,Ay); //A ctx.lineTo(Bx,By);//B ctx.arcTo(new RectF(Bx, By, Cx, Cy), 270, 90); //B-C arc ctx.lineTo(Dx,Dy); //D ctx.arcTo(new RectF(Dx - arc, Dy, Ex + arc, Ey),0,90); //D-E arc ctx.lineTo(Fx, Fy); //E-F ctx.lineTo(Gx, Gy); //F-G ctx.lineTo(Hx, Hy); //G-H ctx.lineTo(Ix, Iy); //H - I ctx.arcTo(new RectF(Jx, Jy, Ix, Iy),90,90);// I = J arc ctx.lineTo(Kx, Ky); //K ctx.arcTo(new RectF(Ax - arc, Ay, Kx + arc, Ky),180,90); //K - A arc ctx.lineTo(Ax, Ay); //K Paint p = new Paint(); p.setAntiAlias(true); p.setColor(0xffffffff); p.setStyle(Style.FILL); canvas.drawPath(ctx, p); p.setColor(0xff000000); p.setStyle(Style.STROKE); p.setStrokeWidth(3); canvas.drawPath(ctx, p);