标签: jetpack-compose-drawscope

如何在 Jetpack composeH 中创建带有弯曲末端的六边形形状

我尝试在jetpack compose中创建六边形形状,但只能实现尖端,尝试了使用quadraticBezierTo和圆弧的多种方法,但无法实现弯曲端部的结果。

我尝试在网上查找,但不完全是我想要的,如果您知道如何实现它,感谢您回答这篇文章。

这是当前没有弯曲末端的代码:

class HexagonShape : Shape {

    override fun createOutline(
        size: Size,
        layoutDirection: LayoutDirection,
        density: Density
    ): Outline {
        return Outline.Generic(
            path = drawCustomHexagonPath(size)
        )
    }
}

private fun drawCustomHexagonPath(size: Size): Path {
    return Path().apply {
        val radius = min(size.width / 2f, size.height / 2f)
        val triangleHeight = (sqrt(3.0) * radius / 2)
        val centerX = size.width / 2
        val centerY = size.height / 2

        moveTo(x = centerX, y = centerY + radius)

        lineTo(x = (centerX - triangleHeight).toFloat(), …
Run Code Online (Sandbox Code Playgroud)

android kotlin android-jetpack-compose android-jetpack-compose-canvas jetpack-compose-drawscope

2
推荐指数
1
解决办法
154
查看次数