Member-only story
Draw an Arc With Canvas In Jetpack Compose.
2 min readMay 3, 2024
In this article we will see how to draw an arc with Canvas in Jetpack Compose.
I have already written few articles on canvas.
To draw an arc , you need two things ,
Canvas
Composable functiondrawArc()
function
@Composable
fun DrawArc() {
Canvas(modifier = Modifier.fillMaxSize()) {
val width = size.width
val height = size.height
drawArc(
color = Color.Red,
topLeft = Offset(width / 2.5f, height / 2),
startAngle = 0f, // 0 represents 3'0 clock
sweepAngle = 180f, // size of the arc
useCenter = false,
style = Stroke(10f),
size = Size(300f, 300f)
)
}
}
As you can see above , we called Canvas
Composable function and provide the full size to the screen.
Also given the color
, topLeft
(position to draw arc), stroke
and size
. Now the main part is startAngle
and sweepAngle
.