背景图像拼贴不填写IOS

问题描述 投票:0回答:1

我在XAML中设置了背景图像:

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="MyApp.Pages.HomePage"
             BackgroundImage="HomePageBackGround.jpg">

这样可以设置背景图像。问题是,在IOS上,图像是平铺的,我希望它能够填满整个屏幕。我怎样才能做到这一点?我已经设置了适当大小的副本(IOS的@ 2x和@ 3x以及Android中的各种可绘制文件夹) - 它在Android上按预期工作,但在IOS上具有平铺行为。

xamarin.forms
1个回答
1
投票

尝试使用RelativeLayout:

使用RelativeLayout和约束表达式,我们可以或多或少地获得与Windows XAML的“Uniform”相同的结果。

<?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="BackGroundImageDemo.StartPage" >
  <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" VerticalOptions="Center"
         HorizontalOptions="Center" FontSize="30"/>
    </Grid>
  </RelativeLayout>
</ContentPage>

这里是the article供参考。

© www.soinside.com 2019 - 2024. All rights reserved.