Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Xamarin.Forms;
- namespace RelativeLayoutExample
- {
- public class MyContentPage : ContentPage
- {
- public MyContentPage()
- {
- RelativeLayout relativeLayout = new RelativeLayout();
- Label upperLeft = new Label
- {
- Text = "Upper Left",
- FontSize = 20
- };
- relativeLayout.Children.Add(
- upperLeft,
- Constraint.Constant(0),
- Constraint.Constant(0));
- Label constantLabel = new Label
- {
- Text = "Constants are Absolute",
- FontSize = 20
- };
- relativeLayout.Children.Add(
- constantLabel,
- Constraint.Constant(100),
- Constraint.Constant(100),
- Constraint.Constant(50),
- Constraint.Constant(200));
- Label halfwayDown = new Label
- {
- Text = "Halfway down and across",
- FontSize = 15
- };
- relativeLayout.Children.Add(
- halfwayDown,
- Constraint.RelativeToParent(
- (Parent) =>
- {
- return Parent.Width / 2;
- }),
- Constraint.RelativeToParent(
- (Parent) =>
- {
- return Parent.Height / 2;
- })
- );
- BoxView boxView = new BoxView
- {
- Color = Color.Accent,
- WidthRequest = 150,
- HeightRequest = 150,
- HorizontalOptions = LayoutOptions.Center,
- VerticalOptions = LayoutOptions.CenterAndExpand
- };
- relativeLayout.Children.Add(
- boxView,
- Constraint.Constant(0), // X
- Constraint.RelativeToParent( // Y
- (Parent) =>
- {
- return Parent.Height / 2;
- }
- ),
- Constraint.RelativeToParent( // width
- (Parent) =>
- {
- return Parent.Width / 2;
- }),
- Constraint.RelativeToParent( // height
- (Parent) =>
- {
- return Parent.Height / 2;
- })
- );
- Content = relativeLayout;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement