4
4
.
.
5
5
.
.
1
1
d
d
r
r
a
a
w
w
A
A
r
r
c
c
I
I
n
n
f
f
o
o
[
[
R
R
]
]
This tutorials shows how to use Canvas to draw an Arc.
Syntax
import androidx.compose.foundation.Canvas
Canvas(Modifier.fillMaxSize()) {
drawArc(
color = Color.Red,
startAngle = 0f,
sweepAngle = 90f,
useCenter = true,
size = Size(width = 300f, height = 300f),
topLeft = Offset(x = 600f, y = 300f)
)
}
E
E
x
x
a
a
m
m
p
p
l
l
e
e
In this example we use Canvas to draw Rectangle.
MainActivity.kt
package com.example.testcompose
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.setContent
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
Canvas(Modifier.fillMaxSize()) {
drawArc(
color = Color.Red,
startAngle = 0f,
sweepAngle = 90f,
useCenter = true,
size = Size(width = 500f, height = 500f),
topLeft = Offset(x = 600f, y = 100f)
)
}
}
}
}
Output