我正在尝试创建一个票证形状。我有一个在X轴上用一个圆创建的源,但我在将其转换到Y轴时遇到了麻烦。如何编辑它以在左右边缘之间创建一个半圆形?
我试过了,但没成功:
private fun getTicketPathVertical(size: Size, density: Density): Path {
val middleY = size.height.div(other = 2f)
val circleRadiusInPx = with(density) { circleRadius.toPx() }
return Path().apply {
reset()
lineTo(x = 0F, y = 0F)
lineTo(x = size.width, y = 0F)
lineTo(x = size.width, y = middleY)
arcTo(
rect = Rect(
left = size.width - circleRadiusInPx * 2,
top = middleY - circleRadiusInPx,
right = size.width,
bottom = middleY + circleRadiusInPx
),
startAngleDegrees = 270f,
sweepAngleDegrees = -180F,
forceMoveTo = false
)
lineTo(x = size.width, y = size.height)
lineTo(0F, size.height)
lineTo(x = 0F, y = size.height)
arcTo(
rect = Rect(
left = 0F,
top = middleY - circleRadiusInPx,
right = circleRadiusInPx * 2,
bottom = middleY + circleRadiusInPx
),
startAngleDegrees = 90f,
sweepAngleDegrees = -180F,
forceMoveTo = false
)
lineTo(x = 0F, y = 0F)
}
}
1条答案
按热度按时间rdrgkggo1#
我解决了这个问题