Skip to content

Instantly share code, notes, and snippets.

@jimmgarrido
Created July 20, 2017 17:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jimmgarrido/2e7d8b647eb6877dba3427da17d7912d to your computer and use it in GitHub Desktop.
Save jimmgarrido/2e7d8b647eb6877dba3427da17d7912d to your computer and use it in GitHub Desktop.
RelativeLayout Center
public TestPage()
{
var mainLayout = new RelativeLayout();
var testLabel = new Label
{
Text = "If you have a corporate notebook, look for the Cisco AnyConnect application. Either in your start menu, on your desktop, or in your taskbar."
};
mainLayout.Children.Add(testLabel, Constraint.RelativeToParent((parent) =>
{
var width = parent.Bounds.Width - 100; //The width you want the Label to be including any padding on the sides
testLabel.WidthRequest = width; //Set Label to the desired width
var final = parent.Bounds.Center.X - (width / 2); //Calculate the X for the Label so it's centered
return final;
}));
Content = mainLayout;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment