为 Android 按钮属性分配负值
我遇到了为 Android 按钮属性指定的负值,如下所示。
android:layout_marginTop="-37px"
有谁知道这到底意味着什么......???提前致谢...
I came across a negative value assigned for an android button proerty as follows.
android:layout_marginTop="-37px"
Does anyone have any idea of what exactly this means...??? Thanks in advance...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
负边距可用于使视图在定位时对布局管理器来说显得更小。
因此,例如,想象一个高度为
h
且 marginTop 为-m
的视图。当此视图定位时,管理器将认为视图的顶部是-m
而不是0
。在线性布局情况下(假设垂直布局),这将导致视图呈现在前一个视图的顶部。您可以在下面的示例中看到这一点,当您减小 textView2 的上边距时,它会覆盖在 textView1 上。
无论这是否是指定行为,我都不能 100% 确定。在此帖子中,Romain Guy提到您可以使用负边距,但是在这个帖子,提到负利润率行为未具体说明。
A negative margin can be used to make a View appear smaller to the layout manager when it is been positioned.
So, for example imagine a View with a height of
h
and a marginTop of-m
. When this view is positioned, the manager will consider the top of the view to be-m
rather the0
. In a linear layout situation (assuming vertical layout), this would cause the view to be rendered on top of the previous view.You can see this in the example below, as you decrease the top margin of the textView2, it becomes overlaid on textView1.
Whether this is specified behaviour or not, I'm not 100% sure. In this post Romain Guy mentions that you can use negative margins, however in this post on Google Groups he mentioned that negative margins behaviour is unspecified.