Skip to content

Instantly share code, notes, and snippets.

@JonDouglas
Created September 10, 2014 20:21
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 JonDouglas/f8b0e3e306b3b9a8371f to your computer and use it in GitHub Desktop.
Save JonDouglas/f8b0e3e306b3b9a8371f to your computer and use it in GitHub Desktop.
FormsRelativeLayout
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