我在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上具有平铺行为。
尝试使用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供参考。