我正在尝试创建需要填充的自定义形状。我无法使用" arcTo"方法,只能使用moveTo,lineTo和addArc。
这是我的代码......
bubblePaintOutline = new Paint();
bubblePaintOutline.setColor(Color.BLACK);
bubblePaintOutline.setStyle(Paint.Style.FILL_AND_STROKE);
bubblePaintOutline.setStrokeWidth(10f);
outlinePath.moveTo(bubbleRect.left, bubbleRect.top);
outlinePath.addArc(new RectF(bubbleRect.left, bubbleRect.top, bubbleRect.left + (2 * margin), bubbleRect.top + (2 * margin)), 180, 90f);
outlinePath.moveTo(bubbleRect.left+(margin),bubbleRect.top);
outlinePath.lineTo(bubbleRect.right-(margin),bubbleRect.top);
outlinePath.addArc(new RectF(bubbleRect.right-(2*margin), bubbleRect.top,bubbleRect.right,bubbleRect.top+(2*margin)),270,90f);
outlinePath.moveTo(bubbleRect.right,bubbleRect.top+margin);
outlinePath.lineTo(bubbleRect.right,bubbleRect.bottom-margin);
outlinePath.addArc(new RectF(bubbleRect.right-(2*margin), bubbleRect.bottom-(2*margin),bubbleRect.right,bubbleRect.bottom),0,90f);
outlinePath.moveTo(bubbleRect.right-margin,bubbleRect.bottom);
outlinePath.lineTo((3.0f/4.0f)*bubbleRect.width()+bubbleRect.left,bubbleRect.bottom);
outlinePath.lineTo(position.x, position.y);
outlinePath.lineTo(position.x,bubbleRect.bottom);
outlinePath.lineTo(bubbleRect.left+margin, bubbleRect.bottom);
outlinePath.addArc(new RectF(bubbleRect.left, bubbleRect.bottom-(2*margin),bubbleRect.left+(2*margin),bubbleRect.bottom),90,90f);
outlinePath.moveTo(bubbleRect.left,bubbleRect.bottom-margin);
outlinePath.lineTo(bubbleRect.left,bubbleRect.top+margin);
outlinePath.moveTo(bubbleRect.left,bubbleRect.top);
outlinePath.close();
代码成功地绘制了我想要的形状并填充了一个小三角形,但是大部分形状没有被填充。 (填充的唯一部分是在2" lineTo" s之间。
如何使用addArc并仍然填充形状?
答案 0 :(得分:0)
在调用moveTo()关闭上一节之前添加对outlinePath.close()的调用