我在您提供的UI中没有看到太多不同之处,但这里有一个很好的经验法则可以遵循:
有时,我们有一个固定大小的合成物.但非常
通常我们也不会.在这些情况下,避免使用硬编码的DP值
,并切换到相对大小,使用
修饰符,如ill MaxSize()、Weight()或WidthIn().
因此,不是因为你的测试手机看起来很酷/正确/很棒而得到Button
分,而是it may not look good or even half rendred on other phones分,因为他们有小屏幕(旧手机)或大屏幕(新手机).
而不是拥有:
@Composable
fun LoginScreen(){
//some code e.g(email and password TextFields)
Button(
onClick={ //do Something },
modifier = Modifier.width(300.dp)
){
Text(....)
}
}
你想要这个:
@Composable
fun LoginScreen(){
//some code e.g(email and password TextFields)
Button(
onClick={ //do Something },
modifier = Modifier.fillMaxWidth()
){
Text(....)
}
}
现在,您可以随心所欲地使用值fillMaxWidth
,而UI将具有the same scale on all screen.
Note: this is aplicable when talking about diffirent sizes of phones if you want to consider your UI to support diffirent devices(Tablets, Foldables, Desktop...) I highly recommende cheking 100