背景图像在xamarin.forms IOS中不成比例

时间:2017-11-20 07:02:18

标签: xamarin xamarin.ios xamarin.forms

我已经使用xamarin.forms创建了一个应用。我刚刚开始测试iOS端,登录屏幕上的背景图像看起来放大了。在android上,图像显示正确。有什么我需要改变才能正确显示它吗?

MainPage.xaml中

<?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="LoyaltyWorx.MainPage"
             BackgroundImage="bk3.jpg"
            >
    <StackLayout VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
        <StackLayout Orientation="Horizontal" VerticalOptions="Start">
            <!-- top controls -->
        </StackLayout>
        <StackLayout VerticalOptions="CenterAndExpand">
            <!-- middle controls -->
            <BoxView HeightRequest="430"></BoxView>
            <Button Text="Continue with Facebook" x:Name="LoginBtn" BackgroundColor="#4867aa" TextColor="White" FontFamily="Klavika" HorizontalOptions="CenterAndExpand" Clicked="LoginBtn_Clicked" />
        </StackLayout>
        <StackLayout Orientation="Horizontal" VerticalOptions="End" HorizontalOptions="Center">
            <!-- bottom controls -->
            <Frame OutlineColor="White" HorizontalOptions="StartAndExpand">
                <StackLayout Orientation="Horizontal" VerticalOptions="End" HorizontalOptions="Center">
                    <!-- bottom controls -->
                    <StackLayout Grid.Row="1" Orientation="Horizontal" Spacing="0">
                        <Label  
                               Text="Terms and conditions"
                              FontSize="13"
                            TextColor="#71757a"
                            FontAttributes="Bold"
                            x:Name="LblTerms"/>
                        <Label  
                            Text=" and"
                            FontSize="13"
                            TextColor="#71757a"
                            />

                        <Label  
                               Text=" privacy policy"
                            FontSize="13"
                            TextColor="#71757a"
                            FontAttributes="Bold"
                            x:Name="LblPrivacy"/>
                    </StackLayout>

                </StackLayout>
            </Frame>
        </StackLayout>
    </StackLayout>
</ContentPage>

iOS和Android中的屏幕截图。 enter image description here enter image description here

1 个答案:

答案 0 :(得分:4)

在IOS中,您无法在ContentPage背景图像上播放太多内容。我将为您提出两种解决方案来摆脱这种情况......

尝试两者并获得与您匹配的内容

解决方案1 ​​

<?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="LoyaltyWorx.MainPage" >
  <RelativeLayout>
    <Image Source="bk3.jpg" 
                RelativeLayout.WidthConstraint=
                  "{ConstraintExpression Type=RelativeToParent, Property=Width}"
                RelativeLayout.HeightConstraint=
                  "{ConstraintExpression Type=RelativeToParent, Property=Height}"/>

                  <PUT YOUR REST OF CODE HERE>

  </RelativeLayout>
</ContentPage>

解决方案2

<?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="LoyaltyWorx.MainPage"
             Padding="0">
    <Grid>
        <Image Source="bk3.jpg" Aspect="AspectFill" />
        <StackLayout>

        <PUT YOUR REST OF CODE HERE>

        </StackLayout>
    </Grid>
</ContentPage>

更新我最适合你的套房....