I want to create or draw the oval shape.
I have done as below
class CustomOvalShape : Shape {
override fun createOutline(
size: androidx.compose.ui.geometry.Size,
layoutDirection: LayoutDirection,
density: androidx.compose.ui.unit.Density
): Outline {
val path = Path().apply {
val rect = Rect(0f, 0f, size.width, size.height)
addOval(rect)
}
return Outline.Generic(path)
}
}
I am using jetpack compose kotlin and when I am using above class I am getting an error as below:
Inheritance from an interface with '@JvmDefault' members is only allowed with -Xjvm-default option
How can I fix this?
draw an oval shape using Kotlin Compose as below-
@Composable
fun OvalShape() {
Canvas(modifier = Modifier.fillMaxSize()) {
val centerX = size.width / 2
val centerY = size.height / 2
val radiusX = size.width / 2
val radiusY = size.height / 2
drawOval(
color = Color.Blue,
topLeft = Offset(centerX - radiusX, centerY - radiusY),
size = Size(radiusX * 2, radiusY * 2),
style = Stroke(width = 2.dp.toPx())
)
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.