Relative layout works on android but not on iOS

jabsaidijabsaidi Member ✭✭
edited March 6 in Xamarin.iOS

Hey guys, I'm using a RelativeLayout in my application to have a text displayed over an image. On android it works just fine, but on iOS it doesn't. The image I have is relatively big and I want to make it fit in a stacklayout that is smaller than it is. So I am using Aspect="Fill" to have the image fill out the stacklayout and not overflow it. On Android it works just fine, but not on iOS.

Here is what it looks like:

So What I did is use the OnPlatform tag to give the aspect different values on iOS and on Android, but it doesn't behave the way I want it to. I tried all of them and none of hem give what I want. Here is a look of the closest one: Aspect="AspectFill"

Here is what my XAML looks like:

<RelativeLayout BackgroundColor="#E2E2E2" HeightRequest="210" HorizontalOptions="Fill">
    <Image Source="support.jpg">
        <Image.Aspect>
            <OnPlatform x:TypeArguments="Aspect" iOS="AspectFill" Android="Fill"/>
        </Image.Aspect>
    </Image>
    <StackLayout HorizontalOptions="FillAndExpand" BackgroundColor="#E0E0E0" Opacity=".6" Padding="10,5,10,5">
        <StackLayout.TranslationY>
            <OnPlatform x:TypeArguments="x:Double" iOS="160" Android="165"/>
        </StackLayout.TranslationY>
        <Label XAlign="Center" TextColor="Black" VerticalTextAlignment="Center" HorizontalOptions="CenterAndExpand" 
                Text="If you have feedback / comments or want to report a problem please contact us"/>
    </StackLayout>
</RelativeLayout>

I want the iOS to look just like the android version of my app, so I need to use the Aspect as "Fill". But it goes over the limit of my highRequest of 210... How can I make it fit?

Thanks

Best Answer

Answers

  • jabsaidijabsaidi Member ✭✭

    @LandLu The content is stretched and that's not really the look I was looking for, but for now that should do it. Thanks a lot! Would you happen to have any other idea how I could do it without stretching the image?

  • LandLuLandLu Member, Xamarin Team Xamurai

    @jabsaidi You could change the Aspect Mode to AspectFill or AspectFit to fit your request.

  • jabsaidijabsaidi Member ✭✭

    @LandLu Cool little hack in using the grid instead of relative layout! Thanks a lot!

Sign In or Register to comment.