Skip to content

Instantly share code, notes, and snippets.

@saamerm
Last active July 1, 2016 16:45
Show Gist options
  • Save saamerm/ea84e94dcbda867bbf9b1460f0fdea74 to your computer and use it in GitHub Desktop.
Save saamerm/ea84e94dcbda867bbf9b1460f0fdea74 to your computer and use it in GitHub Desktop.
Using Relative Layout with an alternate method of calling the class.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xamarin.Forms;
namespace App6
{
public class App : Application
{
public App()
{
MainPage = new RelativeLayoutExample();
}
}
public class RelativeLayoutExample : ContentPage
{
public RelativeLayoutExample()
{
this.Padding = new Thickness(10, Device.OnPlatform(20, 0, 0), 10, 5);
Label heading = new Label {Text = "RelativeLayout Example",TextColor = Color.Red,};
Label relativelyPositioned = new Label{Text = "Positioned relative to my parent."};
RelativeLayout relativeLayout = new RelativeLayout();
relativeLayout.Children.Add(heading, Constraint.RelativeToParent((parent) => {
return 0;
}));
relativeLayout.Children.Add(relativelyPositioned,
Constraint.RelativeToParent((parent) => {
return parent.Width / 3;
}),
Constraint.RelativeToParent((parent) => {
return parent.Height / 2;
}));
this.Content = relativeLayout;
}
}
}
@saamerm
Copy link
Author

saamerm commented Jul 1, 2016

relativelayout

Relative Layout screenshot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment