[英]why padding from top gets different length value based on element's alignment?
Lets say i have two screnario have divider's that get padding from top.可以说我有两个场景有分隔符,从顶部填充。
First scenario (Aligment.TopCenter);第一种情况(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);第二种情况(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?问题是:为什么 a 不等于 b,即使两者具有相同的填充?
Modifier.padding
increases the size of the view. Modifier.padding
增加视图的大小。 And when it is placed in the center of the Box
, 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.当它放在
Box
的中心时,看起来只应用了一半的填充,但视图的另一半位于屏幕的上半部分。
You can add border to see what's actually going on here:您可以添加边框以查看此处实际发生的情况:
Box(
modifier = Modifier.fillMaxSize(),
contentAlignment = Alignment.Center
) {
Divider(
thickness = 3.dp,
color = Color.Red)
Divider(
modifier = Modifier.border(2.dp, color = Color.Green).padding(top = 200.dp),
thickness = 3.dp,
color = Color.Black)
}
You can use Modifier.offset
instead to get the result you expect您可以改用
Modifier.offset
来获得您期望的结果
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.