自定义视图,尝试使用路径进行绘制

时间:2019-02-27 08:06:38

标签: java android android-canvas android-shape

enter image description here

我正在尝试在自定义视图中绘制此自定义形状。我必须中风并填充此形状。

现在我用2种形状制成了,但是我当然没有抚摸过: enter image description here

    rect.set(0, 0, width, height);
    canvas.drawRoundRect(rect, cornerRadius, cornerRadius, paint);
    path.moveTo(x, y);
    ...
    path.close();
    canvas.drawPath(path, paint);

如何使用Path绘制带有笔触的完整形状,这是真的吗?

1 个答案:

答案 0 :(得分:1)

要描画路径,应在用于路径的绘画上设置描边:

val paint = Paint()
paint.style = Paint.Style.STROKE
paint.strokeWidth = BASE_STROKE_WIDTH
paint.isAntiAlias = true
paint.color = ContextCompat.getColor(context, R.color.your_color)

companion object {
  const val BASE_STROKE_WIDTH = 20.0f
}