我想知道如何使用 Jetpack Compose 获取屏幕宽度和高度?无论如何你可以检索屏幕尺寸以外的东西
getWindowManager().getDefaultDisplay()
吗?
提前致谢...
我想知道如何使用 Jetpack Compose 获取屏幕宽度和高度?无论如何你可以检索屏幕尺寸以外的东西
getWindowManager().getDefaultDisplay()
吗?
提前致谢...
您可以通过以下方式实现LocalConfiguration.current
:
@Composable
fun PostView() {
val configuration = LocalConfiguration.current
val screenHeight = configuration.screenHeightDp.dp
val screenWidth = configuration.screenWidthDp.dp
...
}
其他解决方法包括:-
BoxWithConstraints
A.)在层次结构的最高级别声明 a ,然后访问maxHeight
在框范围内公开的和等效宽度属性
B.) 使用自定义布局
Layout(
content = { ... }
){ measurables, constraints ->
//Exposes constraints.maxWidth, and a height equivalent
}