Draw Circle With Canvas In Jetpack Compose.
4 min readJan 7, 2024
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)
)