gpt4 book ai didi

android - 如何使 Canvas 上的圆弧居中 - Jetpack Compose?

转载 作者:行者123 更新时间:2023-12-04 23:54:05 27 4
gpt4 key购买 nike

我不确定如何进行计算才能使这条弧线在 Canvas 上居中?有人可以指出正确的方向吗?

Canvas(modifier = Modifier
.background(Color.LightGray)
.fillMaxWidth()
.height(300.dp)
) {
drawArc(
color = Color.Blue,
startAngle = 30f,
sweepAngle = 300f,
useCenter = false,
style = Stroke(width = 50f, cap = StrokeCap.Round),
size = size/2.25F
)
}

最佳答案

drawArc 方法中使用topLeft 参数。

类似于:

    val sizeArc = size/2.25F
drawArc(
color = Color.Blue,
startAngle = 30f,
sweepAngle = 300f,
topLeft = Offset((size.width - sizeArc.width)/2f,(size.height - sizeArc.height)/2f),
useCenter = false,
style = Stroke(width = 50f, cap = StrokeCap.Round),
size = sizeArc
)

enter image description here

关于android - 如何使 Canvas 上的圆弧居中 - Jetpack Compose?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69087756/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com