我使用 path.cubicTo() 方法画了一颗心
Canvas(modifier = Modifier.size(100.dp)) {
val path = Path()
path.moveTo(0f, size.height / 3)
path.cubicTo(0f, 0f, size.width / 2, 0f, size.width / 2, size.height / 3)
path.cubicTo(size.width / 2, 0f, size.width, 0f, size.width, size.height / 3)
path.cubicTo(
size.width,
size.height * 2 / 3,
size.width / 2,
size.height,
size.width / 2,
size.height
)
path.cubicTo(
0f,
size.height * 2 / 3,
0f,
size.height / 2,
0f,
size.height / 3
)
drawPath(color = Color.Red, path = path, style = Stroke(5f))
}
Run Code Online (Sandbox Code Playgroud)
animation android android-canvas android-jetpack-compose android-jetpack-compose-canvas