Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

Which layout should I use for positioning two elements centered on top of eachother?

$
0
0

Let's say that I want to create something that looks like this, where there are two elements stacked on eachother, and aligned to the center.

button

I'm not really sure what layout should I use for this, and if this could be solved using Horizontal/VerticalLayoutOptions = LayoutOptions.CenterAndExpand? Actually this leads me to second question ... which layout obeys which layout options? It seems that AbsoluteLayout and RelativeLayout simply ignore those altogether, or maybe I'm using them wrong? Here's a sample code which doesn't work as expected.

var button = new Button
{
    HorizontalOptions = LayoutOptions.Center,
    VerticalOptions = LayoutOptions.Center
};

var layout = new RelativeLayout();
layout.Children.Add(background, Constraint.Constant(0), Constraint.Constant(0));
layout.Children.Add(button, Constraint.Constant(0), Constraint.Constant(0));

Any tips on approaching this problem are welcome. I know how to solve this by brute force calculating everything based on dimentions. I should note that I don't want to do something like layout.Children.Add(button, () => layout.Bounds), since that would expand the button to be the same size as the layout. I want to have the option to just center it, without expanding.


Viewing all articles
Browse latest Browse all 58056

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>