Does Android fill part of the way?

I have a shape that I draw using a path. I fill this shape with a gradient, and then I need to put another gray area on top of this gradient, depending on%. I use path.quadTo to make my shape, so I don’t know the y coordinates of the top line to cross it correctly. This is what I get when I just set it to maximum y:

Screen shot

The white bar is an image that I am trying to partially fill. The right gray area that I want to save, but I need to get rid of the left gray area. Any ideas? This is what I am trying to do so far:

@Override public void onDraw(Canvas canvas) { Path path = new Path(); Path grayPath = new Path(); float x1,y1,x3,y3,x2,y2; float x1g,x2g; int width = canvas.getWidth(); int height = canvas.getHeight(); gradientPaint.setShader(new LinearGradient(0, height,width,height, new int[]{Color.RED, Color.YELLOW, Color.GREEN}, new float[] {0,0.6f,1}, Shader.TileMode.REPEAT)); x1 = 0; y1 = (float) (height * .90); x2 = (float) (width * .75); y2 = (float) (height * .50); x3 = width; y3 = (float) (height * .10); x2g = (float) (width*.50); //Ramp path.moveTo(x1, y1); path.quadTo(x2, y2, x3, y3); //Down path.lineTo(x3, y1+50); //Back path.lineTo(x1, y1+50); //Up path.lineTo(x1, y1); //Ramp grayPath.moveTo(x1, y1); grayPath.quadTo(x2, y2, x3, y3); //Down grayPath.lineTo(x3, y1+50); //Back grayPath.lineTo(x2g, y1+50); //Up grayPath.lineTo(x2g, y3); grayPath.setFillType(FillType.WINDING); //Draw for shiny fill //canvas.drawPath(path, gradientPaint); //Draw for grayness canvas.drawPath(grayPath, grayPaint); //Draw for stroke! canvas.drawPath(path, strokePaint); } 
+1
source share
1 answer

Circumcision is what I was looking for, and this is a much simpler solution:

 @Override public void onDraw(Canvas canvas) { Path path = new Path(); float x1,y1,x3,y3,x2,y2; int width = canvas.getWidth(); int height = canvas.getHeight(); gradientPaint.setShader(new LinearGradient(0, height,width,height, new int[]{Color.RED, Color.YELLOW, Color.GREEN}, new float[] {0,0.6f,1}, Shader.TileMode.REPEAT)); //Start at the left side, 10% up x1 = 0; y1 = (float) (height * .90); x2 = (float) (width * .75); y2 = (float) (height * .50); x3 = width; y3 = (float) (height * .10); //Ramp path.moveTo(x1, y1); path.quadTo(x2, y2, x3, y3); //Down path.lineTo(x3, y1+50); //Back path.lineTo(x1, y1+50); //Up path.lineTo(x1, y1); //Create Gray Rect with % Rect rect = new Rect((int)(width*.50),0,(int) x3, (int) y1+50); //CLIP IT canvas.clipPath(path); //Draw for shiny fill canvas.drawPath(path, gradientPaint); //Draw for grayness canvas.drawRect(rect, grayPaint); //Draw for stroke! canvas.drawPath(path, strokePaint); } 
+2
source

All Articles