I have read a lot of documentation on Relative Layout but I am not getting exact meaning of Constant and Factor.Can Anybody explain?
You said you've read a lot of documentation, but I think the RelativeLayout documentation gives a good example if you look closer:
This XAML:
<BoxView Color="Green" WidthRequest="50" HeightRequest="50"
RelativeLayout.XConstraint =
"{ConstraintExpression Type=RelativeToParent,
Property=Width,
Factor=0.5,
Constant=-100}"
RelativeLayout.YConstraint =
"{ConstraintExpression Type=RelativeToParent,
Property=Height,
Factor=0.5,
Constant=-100}" />
Does the same as this C#:
layout.Children.Add(box, Constraint.RelativeToParent((parent) =>
{
return (.5 * parent.Width) - 100;
}),
Constraint.RelativeToParent((parent) =>
{
return (.5 * parent.Height) - 100;
}),
Constraint.Constant(50), Constraint.Constant(50));
If you look at the C# code, things may be clearer for you:
Factor
is the factor with which the value will be multipliedConstant
is an offset which will be summed up to your value after it has been multiplied with the factorSo this is the formula:
(factor * value) + constant
An example:
This will result in: (0.5 * 300) - 100 = 50
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With