为什么从顶部填充基于元素的对齐方式获得不同的长度值?
可以说,我有两个screnario有divider,可以从顶部获得填充。
第一个方案(Aligment.topcenter);
Box(
modifier = Modifier.fillMaxSize(),
contentAlignment = Alignment.TopCenter
) {
Divider(
thickness = 3.dp,
color = Color.Red)
Divider(
modifier = Modifier.padding(top = 200.dp),
thickness = 3.dp,
color = Color.Black)
}
屏幕:
第二个方案(Aligment.Center);
Box(
modifier = Modifier.fillMaxSize(),
contentAlignment = Alignment.Center
) {
Divider(
thickness = 3.dp,
color = Color.Red)
Divider(
modifier = Modifier.padding(top = 200.dp),
thickness = 3.dp,
color = Color.Black)
}
}
屏幕:
问题是:为什么A即使两个都有相同的填充,A也不等于B?
Lets say i have two screnario have divider's that get padding from top.
First scenario (Aligment.TopCenter);
Box(
modifier = Modifier.fillMaxSize(),
contentAlignment = Alignment.TopCenter
) {
Divider(
thickness = 3.dp,
color = Color.Red)
Divider(
modifier = Modifier.padding(top = 200.dp),
thickness = 3.dp,
color = Color.Black)
}
Screen:
Second scenario (Aligment.Center);
Box(
modifier = Modifier.fillMaxSize(),
contentAlignment = Alignment.Center
) {
Divider(
thickness = 3.dp,
color = Color.Red)
Divider(
modifier = Modifier.padding(top = 200.dp),
thickness = 3.dp,
color = Color.Black)
}
}
Screen:
Question is: Why a is not equal to b even though both have same padding?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
modifier.padding
增加了视图的大小。当将其放置在box
的中心时,看起来只有一半的填充物被应用,但视图的另一半位于屏幕的上半部分。您可以添加边框以查看实际发生的事情:
您可以使用
modifier.offer.offset.offset
而是要获得您期望的结果Modifier.padding
increases the size of the view. And when it is placed in the center of theBox
, it looks like only half of the padding is applied, but the other half of the view is in the top half of the screen.You can add border to see what's actually going on here:
You can use
Modifier.offset
instead to get the result you expect