How Android @Compose will handle screen size and orientation in Android. I am not able to find suitable answer after googling. Can someone Answer this question.
You can check for orientation like this:
val configuration = LocalConfiguration.current
when(configuration.orientation) {
Configuration.ORIENTATION_LANDSCAPE -> {}
Configuration.ORIENTATION_PORTRAIT -> {}
Configuration.ORIENTATION_SQUARE -> {}
Configuration.ORIENTATION_UNDEFINED -> {}
}
For screen size:
BoxWithConstraints() {
// thats what you can access:
this.maxWidth
this.maxHeight
this.minWidth
this.minHeight
}
With 1.0.x
you can use the BoxWithConstraints
composable to define different ui based on the screen size.
Something like:
BoxWithConstraints {
if (minWidth < 480.dp) {
/* .... */
} else if (minWidth < 720.dp) {
/* .... */
} else {
/* .... */
}
}
To handle the orientation you can use LocalConfiguration
.
Something like:
val configuration = LocalConfiguration.current
when (configuration.orientation) {
Configuration.ORIENTATION_LANDSCAPE -> {
/* ... */
}
else -> {
/* ... */
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With