有两个项目,每个项目占屏幕宽度的一半

Have two items, each taking half the screens width

我有 2 个按钮,我希望它们彼此相邻,每个按钮占据屏幕宽度的一半(带边距)(即无论屏幕尺寸如何,它们的宽度都相同)。

我有以下内容:

contact.Below(auctioneerView, 10f),
contact.AtLeftOf (this, 10f),
contact.ToLeftOf (report, 10f),
contact.Height().EqualTo(50),

report.Below(auctioneerView, 10f),
report.Height().EqualTo(50),
report.AtRightOf (contact, 10f),
report.WithSameRight(this),

我试过使用

设置宽度
report.Width().EqualTo(this.Frame.Width - 20f),

但这不起作用,因为我怀疑在建立约束时,view 还没有 width,所以它是 0

如何使用FluentLayout让这两个按钮共享屏幕宽度?

您可以为此使用水平 UIStackView。我刚刚在设计器中对此进行了测试,并且效果很好。您可以设置堆栈视图的约束以水平填充屏幕并将两个按钮添加到其中。然后你可以设置 Distribution 属性 为 Fill Equally。设置 Spacing 属性 将改变两个按钮之间的间距。

Here is an introduction to Stack Views from Xamarin.