喷气背包Compose - 设备尺寸错误

3
当我写下这段代码时:
val widthScreenDp = LocalConfiguration.current.screenWidthDp
val heightScreenDp = LocalConfiguration.current.screenHeightDp
val widthScreenPx = with(LocalDensity.current) { widthScreenDp.dp.toPx() }
val heightScreenPx = with(LocalDensity.current) { heightScreenDp.dp.toPx() }

对于我的小米10手机,结果是1078 x 2117.5而不是1080 x 2340。对于Pixel5模拟器,结果为1078 x 2062...

问题出在哪里?如何在Jetpack Compose中获得设备的完整尺寸?

看起来似乎缺少状态栏/导航栏的高度。

谢谢!

1个回答

2

这是关于screenHeightDp的官方解释:

可用屏幕空间的当前高度,以dp为单位,对应于屏幕高度资源限定符。

状态栏/导航栏可能不是可用空间。

您可以像这样获取屏幕高度:

BoxWithConstraints {
   val screenHeight = maxHeight
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接