- Style.STROKE 描边绘制
- Style.FILL 填充绘制,以画笔的中心线往内绘制填充
- Style.FILL_AND_STROKE,描边与填充同时绘制,
- 另:如果要区分描边与填充的颜色,则可以参考下图
2
&3
的代码。3
是先绘制填充后绘制描边;2
是先描边后填充,则线条宽度被填充覆盖了一般; - path.rewind() 不修改之前的绘制状态,重置path的路径并保留内部数据结构用以快速复用。
==注意==:若mPath
未闭合,则Style.STROKE
才可以绘制成功;因为未闭合,则不存在内部填充的概念。
lineToAndStyle.png
//第一个
mPath.reset()
mPath.moveTo(50f, 50f)
mPath.lineTo(r / 4 - 50, r / 4 - 50)
mPath.lineTo(r / 4 - 50, 50f)
mPath.close()
mPaint.color = Color.parseColor("red")
mPaint.style = Paint.Style.STROKE
canvas.drawPath(mPath, mPaint)
mPath.rewind()//若不在此处调用,那么第一个图形会绘制出第二个的效果,即绘制第一个图形的path状态被覆盖了
mPath.moveTo(r / 4 + 50f, 50f)
mPath.lineTo(2 * r / 4 - 50, r / 4 - 50)
mPath.lineTo(2 * r / 4 - 50, 50f)
mPath.close()
canvas.drawPath(mPath, mPaint)//先绘制线条
mPaint.color = Color.parseColor("grey")
mPaint.style = Paint.Style.FILL
canvas.drawPath(mPath, mPaint)//再绘制填充
mPath.rewind()
mPath.moveTo(2 * r / 4 + 50f, 50f)
mPath.lineTo(3 * r / 4 - 50, r / 4 - 50)
mPath.lineTo(3 * r / 4 - 50, 50f)
mPath.close()
mPaint.color = Color.parseColor("grey")
mPaint.style = Paint.Style.FILL_AND_STROKE
canvas.drawPath(mPath, mPaint)
mPaint.color = Color.parseColor("red")
mPaint.style = Paint.Style.STROKE
canvas.drawPath(mPath, mPaint)
mPath.rewind()
mPath.moveTo(3 * r / 4 + 50f, 50f)
mPath.lineTo(r - 50, r / 4 - 50)
mPath.lineTo(r - 50, 50f)
mPath.close()
mPaint.color = Color.parseColor("red")
mPaint.style = Paint.Style.STROKE
canvas.drawPath(mPath, mPaint)
mPaint.color = Color.parseColor("grey")
mPaint.style = Paint.Style.FILL_AND_STROKE
canvas.drawPath(mPath, mPaint)