4 Replies - 468 Views - Last Post: 02 September 2017 - 05:29 PM Rate Topic: -----

#1 Dialupp  Icon User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 210
  • Joined: 31-October 16

Xamarin RelativeLayout why doesn't image fully scale?

Posted 01 September 2017 - 05:54 AM

With Stacklayout I can fully stretch the image to fill the entire page, however, with RelativeLayout this doesn't work. I used the exact same code which is this:

Xaml code
   <RelativeLayout>
        <Image x:Name="image" Aspect="AspectFill" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"/>
    </RelativeLayout>



C# Code

    image.Source = ImageSource.FromResource("Project.Images.background.jpg");




I also read the documentation on RelativeLayout and still no luck.

Is This A Good Question/Topic? 0
  • +

Replies To: Xamarin RelativeLayout why doesn't image fully scale?

#2 tlhIn`toq  Icon User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6505
  • View blog
  • Posts: 14,362
  • Joined: 02-June 10

Re: Xamarin RelativeLayout why doesn't image fully scale?

Posted 01 September 2017 - 09:36 AM

My two cents worth - Stop using the RelativeLayout altogether.
odds are it isn't really what you're after. There are select situations where you need it, but it shouldn't be the default 'go to' layout you use. They always seem to get people in situations like this where they aren't getting what they expected. The current enterprise-grade solution I'm a part of doesn't have ANY such relative layouts.

Also, I avoid code-behind. You can just bind this in XAML. Maybe it never changes for the lifespan of the app. Maybe it does. But if it does, the binding means you don't have code trying to handle that and keep things synchronized.

My rule of thumb is "If you name a XAML control in XAML for any reason other than referencing from another XAML control (IE: For code behind) - 99% chance that you're heading down the wrong path."
Was This Post Helpful? 0
  • +
  • -

#3 Dialupp  Icon User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 210
  • Joined: 31-October 16

Re: Xamarin RelativeLayout why doesn't image fully scale?

Posted 01 September 2017 - 05:15 PM

Ok, but what is the reason it doesn't scale fully with this layout?
Was This Post Helpful? 0
  • +
  • -

#4 tlhIn`toq  Icon User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6505
  • View blog
  • Posts: 14,362
  • Joined: 02-June 10

Re: Xamarin RelativeLayout why doesn't image fully scale?

Posted 02 September 2017 - 04:56 AM

View PostDialupp, on 01 September 2017 - 06:15 PM, said:

Ok, but what is the reason it doesn't scale fully with this layout?


I don't know. I don't use them because they are unreliable. And without the entire XAML for the view there is no way to know what affect any of the containers are having on it.

That's the nature of XAML - controls, nested in controls, nested in controls... The nested children get influenced by their containing parents. Looking at just one thing doesn't let you see the bigger picture.
Was This Post Helpful? 0
  • +
  • -

#5 Dialupp  Icon User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 210
  • Joined: 31-October 16

Re: Xamarin RelativeLayout why doesn't image fully scale?

Posted 02 September 2017 - 05:29 PM

Ah ok thanks.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1