如何在Xamarin的stackLayout中填充图像全屏?

Sha*_*ala 4 .net c# xaml xamarin.android xamarin

*如何在Xamarin的stackLayout中填充图像全屏? 我无法将Image设置为适合stacklayout .XAML 文件代码

  <StackLayout Padding="0" BackgroundColor="Yellow">
    <Image Source="ic_splash.png" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" > </Image>
  </StackLayout>
</ContentPage>
Run Code Online (Sandbox Code Playgroud)

输出Android和Window Phone的屏幕截图.... 在此输入图像描述 在此输入图像描述 我想在背景中使用图像.*

Sha*_*ala 7

最后我使用下面的代码解决了问题....

<?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>
Run Code Online (Sandbox Code Playgroud)

我使用上面的代码将背景图像设置为适合屏幕....

BackgroundImage="BackgroundImage.png"


gre*_*ene 5

BackgroundImage属性的问题是图像比例可能会随着屏幕尺寸的变化而变化。

在这里我找到了如何使用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>
Run Code Online (Sandbox Code Playgroud)