Bug: RelativeLayout Not Obeying Padding or LayoutOptions

JLundaJLunda USMember ✭✭

Xamarin Team,

I have been trying to use RelativeLayout for my application, and I've also been trying to abstract the Padding and LayoutOptions for this layout to an application-level ResourceDictionary.

I've tried simplifying this down to a very simple case where I have the following in my application-level ResourceDictionary:
`<Application.Resources>


  <LayoutOptions x:Key="RelativeLayout_HorizontalOptions"
                 Alignment="End"
                 Expands="True" />

  <LayoutOptions x:Key="RelativeLayout_VerticalOptions"
    Alignment="Start"
    Expands="False" />
</ResourceDictionary>

</Application.Resources>`

And I have the following markup in my RelativeLayout:
<RelativeLayout Padding="50" BackgroundColor="Red" HorizontalOptions="{StaticResource RelativeLayout_HorizontalOptions}" VerticalOptions="{StaticResource RelativeLayout_VerticalOptions}"> <Label Text="Test Label" /> </RelativeLayout>

When the layout is a RelativeLayout the padding is not obeyed at all, but the Alignment for the LayoutOptions is obeyed, while the Expands Boolean is not obeyed. I originally thought this may be because of an inability to parse a String to a Boolean, but this is not the case, as far as I can tell, since the example here shows LayoutOptions done in exactly this way, and the Boolean structure documentation clearly states that the String representation of a Boolean is either "True" or "False", in order for it to be parse-able.

Switching the RelativeLayout to a StackLayout causes the Padding StaticResource definition to be obeyed, but, just as in the case of RelativeLayout, the StackLayout only obeys the Alignment property of the LayoutOptions StaticResource and not the Expands property.

Please look into this bug, since it is at such a fundamental level.

Posts

  • shihaonanshihaonan Member ✭✭

    5-24-2018 this issue still exists. :/

  • SuperCorksSuperCorks Member ✭✭

    Still ongoing (2019-01-15)

  • SuperCorksSuperCorks Member ✭✭

    PS. To solve this issue, just wrap the relative layout in a stack layout

    <StackLayout
        VerticalOptions="FillAndExpand"
        HorizontalOptions="FillAndExpand"
    >
        <!-- Wrapping the relative layout in a stack layout because Relative layout includes
                the padding of the parent when calculating height. Ugh...
         -->
        <RelativeLayout
               VerticalOptions="FillAndExpand"
               HorizontalOptions="FillAndExpand"
         >
         YOUR CONTENT HERE
         </RelativeLayout>
    </StackLayout>
    
Sign In or Register to comment.