how to Fill Image fullscreen in stackLayout in Xamarin?

21,632

Solution 1

Finally I solved problem using below code....

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
                       xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                       x:Class="Your.Namespace.Views.LoginView"
             Title="{Binding Title}"
             BackgroundImage="BackgroundImage.png">
  <StackLayout>
    <!-- Your stuff goes here -->
  </StackLayout>
</ContentPage>

I have set background Image as fit to screen using above code....

BackgroundImage="BackgroundImage.png"

Solution 2

The problem with the BackgroundImage property is that the image proportion could change on screen size changed.

Here I found how to fill all the screen and save proportions using RelativeLayout:

<RelativeLayout>
  <Image Source="Jupiter.png" Opacity="0.3"
              RelativeLayout.WidthConstraint=
                "{ConstraintExpression Type=RelativeToParent, Property=Width}"
              RelativeLayout.HeightConstraint=
                "{ConstraintExpression Type=RelativeToParent, Property=Height}"/>
  <Grid RelativeLayout.WidthConstraint=
            "{ConstraintExpression Type=RelativeToParent, Property=Width}"
          RelativeLayout.HeightConstraint=
            "{ConstraintExpression Type=RelativeToParent, Property=Height}">

    <Label Text="Hello world from XAML"/>
  </Grid>
</RelativeLayout>

Solution 3

Or with your first code you could set the image property aspect to AspectFill this would eventually crop your image though while maintaining the aspect ratio.

<StackLayout Padding="0" BackgroundColor="Yellow">
<Image Source="ic_splash.png" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Aspect="AspectFill" > </Image>

Solution 4

because there is no physical key on your android emulator. by using a emulator with physical key will be well

Share:
21,632
Shahabuddin Vansiwala
Author by

Shahabuddin Vansiwala

Updated on May 17, 2020

Comments

  • Shahabuddin Vansiwala
    Shahabuddin Vansiwala almost 4 years

    *how to Fill Image fullscreen in stackLayout in Xamarin ? I can't set Image in fit to stacklayout .XAML File Code

      <StackLayout Padding="0" BackgroundColor="Yellow">
        <Image Source="ic_splash.png" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" > </Image>
      </StackLayout>
    </ContentPage>
    

    Screenshot of Output Android and Window Phone.... enter image description here enter image description here I want to fit Image in Background.*