public App() { usernameentry = new MyEntry (); usernameentry.WidthRequest = 100; usernameentry.HeightRequest = 40; usernameentry.Placeholder="username"; usernameentry.Top = 10; usernameentry.BackgroundColor = Color.Yellow; passentry = new MyEntry (); passentry.WidthRequest = 100; passentry.HeightRequest = 40; passentry.Placeholder = "Password"; passentry.MarginTop = 20; passentry.BackgroundColor = Color.FromRgb (102, 204, 255); myStacklayout stacklayout = new myStacklayout (); stacklayout.BackgroundColor=Color.FromRgb (170, 221, 255); stacklayout.WidthRequest = 200; stacklayout.HeightRequest = 100; stacklayout.Top = 200; stacklayout.addview (usernameentry); stacklayout.addview (passentry); relativelayout.addview (stacklayout); okbut = new MyButton (); okbut.HeightRequest = 40; okbut.WidthRequest = 100; okbut.Top = 400; okbut.Text="Ok"; okbut.TextColor=Color.FromRgb (102, 204, 255); okbut.BorderColor= Color.FromRgb (102, 204, 255); okbut.BorderRadius = 2; okbut.BackgroundColor= Color.White; okbut.BorderWidth = 1; relativelayout.addview (okbut); }
public void addview(MyButton but) { Constraint y=Constraint.RelativeToParent ( (parent) => { return parent.Height / 2 - but.HeightRequest/2; } ); Constraint x=Constraint.RelativeToParent ( (parent) => { return parent.Width / 2 - but.WidthRequest/2; } ); if (but.Top.HasValue) { y = Constraint.RelativeToParent ( (parent) => { return but.Top.HasValue?but.Top.Value:0; } ); } if (but.Left.HasValue) { x = Constraint.RelativeToParent ( (parent) => { return but.Left.HasValue ? but.Left.Value : 0; }); } else { x = Constraint.RelativeToParent ( (parent) => { return parent.Width / 2 - but.WidthRequest/2; }); } this.Children.Add (but, x, y); }