Я делаю один пример о RelativeLayout, вы можете посмотреть:
<RelativeLayout x:Name="layout">
<BoxView
x:Name="redBox"
RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent,
Property=Height,
Factor=.8,
Constant=0}"
RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent,
Property=Width,
Factor=1,
Constant=0}"
RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent,
Property=Height,
Factor=.15,
Constant=0}"
Color="Red" />
<BoxView x:Name="blueBox" Color="Blue" />
</RelativeLayout>
public Page5 ()
{
InitializeComponent ();
double valuex = (double)Application.Current.Resources["TargetXConstant"];
double valuey = (double)Application.Current.Resources["TargetYConstant"];
**layout.Children.Add(blueBox, Constraint.RelativeToView(redBox, (Parent, sibling) => {
return sibling.X + valuex;
}), Constraint.RelativeToView(redBox, (parent, sibling) => {
return sibling.Y + valuey;
}), Constraint.RelativeToParent((parent) => {
return parent.Width * .5;
}), Constraint.RelativeToParent((parent) => {
return parent.Height * .5;
}));**
}
Ресурс находится в App.xaml:
<Application.Resources>
<ResourceDictionary>
<x:Double x:Key="TargetXConstant">40</x:Double>
<x:Double x:Key="TargetYConstant">40</x:Double>
</ResourceDictionary>
</Application.Resources>
Жирная часть соответствует xaml:
<BoxView
x:Name="blueBox"
RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent,
Property=Height,
Factor=.5,
Constant=0}"
RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent,
Property=Width,
Factor=.5,
Constant=0}"
RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToView,
ElementName=redBox,
Property=X,
Factor=1,
Constant={StaticResource TargetXConstant}}"
RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToView,
ElementName=redBox,
Property=Y,
Factor=1,
Constant={StaticResource TargetYConstant}}"
Color="Blue" />
Вы также можете посмотреть RelativeLayout:
https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/layouts/relative-layout