【问题标题】:Background Image out of proportion in xamarin.forms IOSxamarin.forms IOS中的背景图像不成比例
【发布时间】:2017-11-20 07:02:17
【问题描述】:

我使用 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 的屏幕截图。

【问题讨论】:

  • 这都是一张背景图片吗?除了facebook登录按钮和其他底部按钮
  • 是的,它是一张背景图片。我刚刚添加了 Facebook 按钮以及底部的条款和条件
  • 我不认为你可以使用内容页面背景图像,我建议使用相对布局和背景图像,如果你需要我可以在这里发布一些示例代码
  • 啊,我明白了,是的,我会很感激示例代码。谢谢
  • xamarin.com/schemas/2014/forms" xmlns:x="schemas.microsoft.com/winfx/2009/xaml" x:Class="LoyaltyWorx. MainPage" >

标签: xamarin xamarin.ios xamarin.forms


【解决方案1】:

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

两者都试一下,得到最适合你的东西

解决方案 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>

告诉我你最好的套件......

【讨论】:

  • 您好 Shiwanka,请查看stackoverflow.com/questions/47387836/…。我也在我的 gridView 上尝试了你的解决方案作为背景图像,但无济于事。如果您能提供帮助,谢谢,谢谢
猜你喜欢
  • 1970-01-01
  • 2017-10-05
  • 1970-01-01
  • 2019-12-01
  • 2019-01-04
  • 1970-01-01
  • 2017-07-25
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多