0

I have 2 buttons that I want to have next to each other, each taking up half the width of the screen (with margins) (i.e. they are the same width no matter what the screen size).

I have the following:

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),

I have tried setting the width using

report.Width().EqualTo(this.Frame.Width - 20f),

But that doesn't work as I suspect that at the time that the constraints are built up, the view doesn't have a width yet so it is 0

How can I use FluentLayout to get these two buttons to share the width of the screen?

David Pilkington
  • 13,528
  • 3
  • 41
  • 73

1 Answers1

1

You could use a horizontal UIStackView for this. I just tested this in the designer and it works quite well. You can set the constraints for the stack view to fill the screen horizontally and add the two buttons to it. Then you can set the Distribution property to Fill Equally. Setting the Spacing property will change the spacing between the two buttons.

Here is an introduction to Stack Views from Xamarin.

Jordan Harris
  • 380
  • 2
  • 7