C# 对背景图像使用AbsoluteLayout,但某些元素未正确定位Xamarin表单

C# 对背景图像使用AbsoluteLayout,但某些元素未正确定位Xamarin表单,c#,xaml,xamarin,xamarin.forms,C#,Xaml,Xamarin,Xamarin.forms,我有一个背景图像,我必须设置到我的内容页,但是图像被放大了。我需要它在Aspect=“Fill”上,以便正确显示。我在网上看了看,解决办法是要么有一个绝对的布局,要么有一个相对的图片。但当添加此项时,本应位于页面底部的图像不再存在 <RelativeLayout Parent="0" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"> <Image Source="Background.

我有一个背景图像,我必须设置到我的内容页,但是图像被放大了。我需要它在Aspect=“Fill”上,以便正确显示。我在网上看了看,解决办法是要么有一个绝对的布局,要么有一个相对的图片。但当添加此项时,本应位于页面底部的图像不再存在

<RelativeLayout Parent="0" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">

    <Image Source="Background.jpg" Aspect="Fill" RelativeLayout.WidthConstraint= "{ConstraintExpression Type=RelativeToParent, Property=Width}"
            RelativeLayout.HeightConstraint= "{ConstraintExpression Type=RelativeToParent, Property=Height}"></Image>

    <StackLayout>

        <Label Text="Timetable" TextColor="Silver" HorizontalOptions="EndAndExpand" Margin="0, 10, 20, 0">
        </Label>

        <Image Margin="15, 20" HorizontalOptions="Center" WidthRequest="350" Source="subtle-logo.png"></Image>

        <Image HorizontalOptions="Center" x:Name="PlayPauseButton" Source="play.png" WidthRequest="75">
        </Image>

        <Image HorizontalOptions="Center" x:Name="shareButton" Source="share-button.png" WidthRequest="50" 
               VerticalOptions="End" Margin="0, 0, 0, 20">
        </Image>

    </StackLayout>

   </RelativeLayout> 


但是,由于VerticalOptions=“End”属性,该共享按钮应位于页面底部。如何修复此问题?

出于性能原因,AbsoluteLayout更好。另外,您询问的是
AbsoluteLayout
,但在共享的代码中使用了
RelativeLayout

无论如何,最后一幅图像需要使用
VerticalOptions
将其设置为
VerticalOptions=“EndAndExpand”
,这将扩展该区域以填充可用空间,然后将图像放置在该区域的垂直端

基本上,
开始
中心
结束
,和
填充
布局选项说明在可用空间中放置元素的位置,或者是否放大元素以填充可用空间,其中
开始展开
中心展开
结束展开
,如果可能的话,
FillAndExpand
将扩展可用空间,然后将该空间中的项目设置为
Start
Center
等。
和expand
选项仅适用于
堆栈布局

如果您想使用
AbsoluteLayout
代替(),下面是代码:


<AbsoluteLayout>

    <Image Source="Background.jpg" Aspect="AspectFill" AbsoluteLayout.LayoutBounds="0,0,1,1" AbsoluteLayout.LayoutFlags="All" />

    <StackLayout AbsoluteLayout.LayoutBounds="0,0,1,1" AbsoluteLayout.LayoutFlags="All">

        <Label Text="Timetable" TextColor="Silver" HorizontalOptions="EndAndExpand" Margin="0, 10, 20, 0">
        </Label>

        <Image Margin="15, 20" HorizontalOptions="Center" WidthRequest="350" Source="subtle-logo.png"></Image>

        <Image HorizontalOptions="Center" x:Name="PlayPauseButton" Source="play.png" WidthRequest="75">
        </Image>

        <Image HorizontalOptions="Center" x:Name="shareButton" Source="share-button.png" WidthRequest="50" 
               VerticalOptions="EndAndExpand" Margin="0, 0, 0, 20">
        </Image>

    </StackLayout>

</AbsoluteLayout>