Member-only story

Draw an Arc With Canvas In Jetpack Compose.

Jayant Kumar🇮🇳
2 min readMay 3, 2024

--

Photo by SpaceX on Unsplash

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 function
  • drawArc() 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 .

--

--

Jayant Kumar🇮🇳
Jayant Kumar🇮🇳

Written by Jayant Kumar🇮🇳

Hello My name is Jayant Kumar, I am a software Engineer , specialist in Mobile Development (Android , IOS , Flutter , React Native and Ionic) from India 🇮🇳

No responses yet