title: Xamarin Forms relative layout - get a stack layout centred inside
body: <p>I have a Xamarin forms application where I use a relative layout to get some elements positioned very specifically. I want to have a stack layout centred right in the middle of the relative layout.  I use this code: </p>
  
  <pre><code>_relativeLayout.Children.Add (
          _stackLayout, 
          Constraint.RelativeToParent(p =&gt; (p.Width / 2) - (_stackLayout.Width / 2) ),
          Constraint.RelativeToParent(p =&gt; (p.Height/ 2) - (_stackLayout.Height / 2) )
  
      );
  </code></pre>
  
  <p>When the form loads, I do not get the right result. The stack layout is way off to one side. However, if I rotate the screen one way and then back again, it looks perfect. So I gather that when the layout is rendered, the height and width of the stack layout have not yet been fully calculated, but on rotation these values are known so it renders properly. </p>
  
  <p>How can I get the stack layout perfectly centred on initial form load? </p>