Do LayoutOptions work with RelativeLayout in XAML?

JLundaJLunda USMember ✭✭
edited January 2017 in Xamarin.Forms

I am trying to do a very simple layout test for a XAML implementation of RelativeLayout with LayoutOptions specified for the controls on the page (which should be possible, as far as I understand, since they also inherit from the View class). Please see the below XAML and let me know if there are just problems with it, but if there are no problems, please tell me whether or not RelativeLayout supports LayoutOptions.

Also, I understand that I can use X and Y Constraints or Height and Width Contraints to define these boundaries and positions, but for simple positioning of controls, I would rather use the LayoutOptions while still maintaining the use of a RelativeLayout (rather than a simpler StackLayout) for more advanced positioning when I want it.

    <?xml version="1.0" encoding="utf-8" ?>
    <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
                 xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                 xmlns:local="clr-namespace:AppName.ViewModels;assembly=AppName"
                 x:Class="AppName.Pages.HomePage"
                 Title="AppName">
      <ContentPage.BindingContext>
        <local:HomePageViewModel />
      </ContentPage.BindingContext>
      <RelativeLayout Padding="15" VerticalOptions="StartAndExpand" HorizontalOptions="StartAndExpand">
        <Label x:Name="MainText"
               Text="{Binding MainText}"
               VerticalOptions="End"
               HorizontalOptions="CenterAndExpand">
        </Label>
      </RelativeLayout>
    </ContentPage>

Any insights are appreciated. Thanks!

Answers

  • Patil2421Patil2421 USMember ✭✭✭

    @JLunda
    Yes you are right the layout options will work with relative layouts. But for the perfect positioning you should use the constraints.

  • JLundaJLunda USMember ✭✭
    Well that's just it though: the above markup is not working. The RelativeLayout is not obeying the LayoutOptions when I pride the above markup, but it will obey constraints. Also, I do not receive an error; the options are just not obeyed. Can you provide any help?
Sign In or Register to comment.