Xamarin.Forms.RelativeLayout Class
A Xamarin.Forms.Layout`1 that uses Xamarin.Forms.Constraints to layout its children.

See Also: RelativeLayout Members

Syntax

public class RelativeLayout : Layout<View>

Remarks

The RelativeLayoutExample class in the following code extends the Xamarin.Forms.ContentPage class by adding a Xamarin.Forms.RelativeLayout that contains a heading and another label. Both labels are positioned relative to the Xamarin.Forms.ContentPage:

C# Example

public class RelativeLayoutExample : ContentPage
{
    public RelativeLayoutExample ()
    {
        this.Padding = new Thickness (10, Device.OnPlatform (20, 0, 0), 10, 5);

        Label heading = new Label {
            Text = "RelativeLayout Example",
            TextColor = Color.Red,
        };

        Label relativelyPositioned = new Label {
            Text = "Positioned relative to my parent."
        };

        RelativeLayout relativeLayout = new RelativeLayout ();

        relativeLayout.Children.Add (heading, Constraint.RelativeToParent ((parent) => {
            return 0;
        }));

        relativeLayout.Children.Add (relativelyPositioned,
            Constraint.RelativeToParent ((parent) => {
                return parent.Width / 3;
            }),
            Constraint.RelativeToParent ((parent) => {
                return parent.Height / 2;
            }));
        this.Content = relativeLayout;
    }
}

For a more complete example that exercises many more of the layout options for the Xamarin.Forms.RelativeLayout class, see the FormsGallery sample that can be found on the Sample Applications page.

The Xamarin.Forms.RelativeLayout class has the following XAML attached properties:

AttachedPropertyValue
XConstraint

XAML markup extension for a constraint expression. See Xamarin.Forms.ConstraintExpression.

YConstraint

XAML markup extension for a constraint expression. See Xamarin.Forms.ConstraintExpression.

WidthConstraint

XAML markup extension for a constraint expression. See Xamarin.Forms.ConstraintExpression.

HeightConstraint

XAML markup extension for a constraint expression. See Xamarin.Forms.ConstraintExpression.

Requirements

Namespace: Xamarin.Forms
Assembly: Xamarin.Forms.Core (in Xamarin.Forms.Core.dll)
Assembly Versions: 1.0.0.0, 1.1.0.0, 1.2.0.0, 1.3.0.0