I have a requirement where I need to align some buttons within a fixed area of the screen. The chosen layout behaves/looks as follows;
Specifically, I need a 3 button layout where the buttons reach the edges, a 2 button layout that has equals spacing between buttons and to the edge of the container, and a single button layout that's just simply centred.
I've tried/considered;
- Negative margin on container, positive margin on buttons. (Problem is that the "2 button" layout does not have equal spacing)
- Manually calculating the margins for each control based on the number of elements in the collection using IValueConverters (Problem is that it seems overly complicated for what I'm trying to achieve, lots of maths..)
- Creating 3 separate layouts and choosing the correct one based on collection size. (Problem because it feels so, so, so very hacky)
Key Points:
- For layout 2, the gaps between the buttons should be equal to the size of the gap that reaches to the edge of the container (see the second layout in image).
- There is a logic swap between layout 2 and 3, layout 3 doesn't have "outside gaps", it only has gaps between each button.
- There is no 4 layout, no requirement for it.
So my question is: What's the "correct" way to achieve this spacing requirement? I'm looking for a simple and fairly standard way to do it.
Conclusion:
I thought it might be interesting to note that I ended up not being able to do this. The mathsy solution and the "custom control" solutions would have worked if I'd tried harder, but I ended up taking the easy route and just "centralised a listview" and had done with it.