java - 在自定义 View 中绘制描边形状

标签 java android android-canvas android-shape

enter image description here

我正在尝试在自定义 View 中绘制此自定义形状。我必须对这个形状进行描边和填充。

现在我用 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用描边画出完整的形状,是真的吗?

最佳答案

为了描边你的路径,你应该在你为你的路径使用的油漆上设置描边:

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
}

关于java - 在自定义 View 中绘制描边形状,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54900721/

相关文章:

java - 查找二维数组的可能组合

java - 返回给定 JTextPane 位置的行号的方法?

java - 当我在 androidX 中导入 Migrating to the New Places SDK Client 时。无法访问 getPhotoMetadatas() 方法

android - 使用 Path 从 Bitmap 中剪切区域

java - 使用 JSF 中的 Tomahawk 将网页数据转换为 PDF 格式?

java - 获取来自 Gmail 的最后 20 封电子邮件(Java Android)

android - 获取调试日志 - iPhone

android - 获取位置更新,即使我在同一个地方很长时间

android - 使用自定义形状在 Canvas 上绘制位图

android - Android SDK 中的 Rect 和 RectF