Draw Circle With Canvas In Jetpack Compose.

Jayant Kumar🇮🇳
4 min readJan 7, 2024
Photo by Erlend Ekseth on Unsplash

Hello everyone , In this article we will draw a circle through Canvas in Jetpack Compose. I already wrote an article about drawing a line .

To draw a circle you need of two things only —

  • Canvas composable function
  • drawCircle function
@Composable
fun DrawCircle() {

Canvas(modifier = Modifier.fillMaxSize()) {
drawCircle(
color = Color.Red,
radius = size.minDimension / 4,
)
}
}

As you can see above , we called Canvas composable function and given the full size to the screen.

After that called drawCircle() function which will draw the circle.

  • radius will be your size of the circle.

here size.minDimension will find the size of the canvas.

  • By default circle will be drawn at the centre of the screen.

If you want somewhere else on the screen then -

 drawCircle(
color = Color.Red,
radius = size.minDimension / 4,
center = Offset(size.width/2,size.height/4)
)

--

--

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