XF相对控件布局
using System;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
[assembly: XamlCompilation (XamlCompilationOptions.Compile)]
namespace App6
{
public partial class App : Application
{
public App ()
{
InitializeComponent();
BoxView bv = new BoxView { Color = Color.Red, WidthRequest = 150, HeightRequest = 150 };
Label lbl = new Label { Text = "这是一个红色的方块", TextColor = Color.Red };
RelativeLayout rl = new RelativeLayout();
rl.Children.Add(bv,Constraint.RelativeToParent((parent)=>parent.Width/2),Constraint.RelativeToParent((parent)=>parent.Height/2));
rl.Children.Add(lbl, Constraint.RelativeToView(bv, (parent, sibling) => sibling.X+bv.Width), Constraint.RelativeToView(bv, (parent, sibling) => sibling.Y));
MainPage = new ContentPage { Content=rl};
}
protected override void OnStart ()
{
// Handle when your app starts
}
protected override void OnSleep ()
{
// Handle when your app sleeps
}
protected override void OnResume ()
{
// Handle when your app resumes
}
}
}