AndroidAutoSize
AndroidAutoSize copied to clipboard
与compose共用时dialog没法适配
Environment
- [x] Autosize Version: 1.2.1
- [x] Target Android Version: android 10.0
- [x] Device Model: honor10
- [x] Device Resolution: 2280 * 1080
- [x] Design Size On AndroidManifest: 1400 * 1400
Bug Description:
我用compose写ui并用autosize进行适配发现dialog无法适配这个怎么解决
Log:
D/AndroidAutoSize: The com.example.myapplication.MainActivity has been adapted! MainActivity Info: isBaseOnWidth = true, designWidthInDp = 1400.000000, designWidthInSubunits = 1400.000000, targetDensity = 0.771429, targetScaledDensity = 0.771429, targetDensityDpi = 123, targetXdpi = 0.771429, targetScreenWidthDp = 1400, targetScreenHeightDp = 2722
Screenshot
Related Code:
@Composable
fun Greeting(name: String) {
Dialog(onDismissRequest = { }) {
// Draw a rectangle shape with rounded corners inside the dialog
Box(
Modifier
.size(1200.dp, 50.dp)
.background(Color.White)
)
}
}
Others:
我发现在包package androidx.compose.ui.window里这,
@Composable
private fun DialogLayout(
modifier: Modifier = Modifier,
content: @Composable () -> Unit
) {
Layout(
content = content,
modifier = modifier
) { measurables, constraints ->
val placeables = measurables.fastMap { it.measure(constraints) }
val width = placeables.fastMaxBy { it.width }?.width ?: constraints.minWidth
val height = placeables.fastMaxBy { it.height }?.height ?: constraints.minHeight
layout(width, height) {
placeables.fastForEach { it.placeRelative(0, 0) }
}
}
}
这段代码没有找到我输入的1200.dp
compose 没用过,不是很懂,如果是系统 Dialog,参考这里 #1,如果是自己写的 Dialog,可能是尺寸没设置正确,试试使用 AutoSizeUtils.dp2px 传入一个经过计算的 PX
compose 没用过,不是很懂,如果是系统 Dialog,参考这里 #1,如果是自己写的 Dialog,可能是尺寸没设置正确,试试使用 AutoSizeUtils.dp2px 传入一个经过计算的 PX
compose字体适配无效,不知道咋整了,不知道有没其他思路,或者可能compose不适用这套框架
@lanjd @JessYanCoding 解决了吗,我现在也遇到了这个问题,弹框不适配
@lanjd @JessYanCoding 解决了吗,我现在也遇到了这个问题,弹框不适配
有试过把usePlatformDefaultWidth设置为false么:
Dialog(
onDismissRequest = {},
properties = DialogProperties(
usePlatformDefaultWidth = false
)
) {}