在自定义视图中绘制描边形状

问题描述 投票:1回答:1

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绘制完整的形状,是真的吗?

java android android-canvas android-shape
1个回答
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
}
© www.soinside.com 2019 - 2024. All rights reserved.