-
-
Save jimmgarrido/2e7d8b647eb6877dba3427da17d7912d to your computer and use it in GitHub Desktop.
RelativeLayout Center
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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