Created
September 10, 2014 20:21
-
-
Save JonDouglas/f8b0e3e306b3b9a8371f to your computer and use it in GitHub Desktop.
FormsRelativeLayout
This file contains hidden or 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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using Xamarin.Forms; | |
namespace FormsPlayground | |
{ | |
class RelativeLayoutDemoPage : ContentPage | |
{ | |
public RelativeLayoutDemoPage() | |
{ | |
// Create the RelativeLayout | |
RelativeLayout relativeLayout = new RelativeLayout(); | |
// Four BoxView's | |
relativeLayout.Children.Add( | |
new BoxView { Color = Color.Red }, | |
Constraint.Constant(0), | |
Constraint.Constant(0)); | |
relativeLayout.Children.Add( | |
new BoxView { Color = Color.Green }, | |
Constraint.RelativeToParent((parent) => | |
{ | |
return parent.Width - 40; | |
}), | |
Constraint.Constant(0)); | |
relativeLayout.Children.Add( | |
new BoxView { Color = Color.Blue }, | |
Constraint.Constant(0), | |
Constraint.RelativeToParent((parent) => | |
{ | |
return parent.Height - 40; | |
})); | |
relativeLayout.Children.Add( | |
new BoxView { Color = Color.Yellow }, | |
Constraint.RelativeToParent((parent) => | |
{ | |
return parent.Width - 40; | |
}), | |
Constraint.RelativeToParent((parent) => | |
{ | |
return parent.Height - 40; | |
})); | |
// Accomodate iPhone status bar. | |
this.Padding = new Thickness(10, Device.OnPlatform(20, 0, 0), 10, 5); | |
// Build the page. | |
Grid grid = new Grid | |
{ | |
RowDefinitions = | |
{ | |
new RowDefinition { Height = GridLength.Auto }, | |
new RowDefinition { Height = new GridLength(1, GridUnitType.Star)} | |
} | |
}; | |
grid.Children.Add(relativeLayout, 0, 1); | |
Content = grid; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment