如何防止键盘打开时挤压背景图像?

Kit*_*tto 10 xamarin xamarin.forms

我正在使用Xamarin.Forms并且正在瞄准iOSAndroid.

默认视图 没有键盘

键盘打开,背景图像被挤压 键盘打开

背景图像也在景观模式中被挤压 景观

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="XilnexOTM.Views.LoginPage"
             BackgroundImage="bg1.png" >
    <ScrollView>
        <StackLayout Orientation="Vertical">
            <Label Text="PICTURE"  />
            <Label Text="PIC 2" />

            <Entry Placeholder="Username" />
            <Entry Placeholder="Password" IsPassword="true"/>

            <Button x:Name="btn_Login"
                    Text="Login"
                    BackgroundColor="#FF0000"/>

        </StackLayout>
    </ScrollView>
</ContentPage>
Run Code Online (Sandbox Code Playgroud)

是否有任何可能的方法将概念CSS应用于Xamarin.Forms

xx {
 background-size: cover;
 background-position: right bottom;
}
Run Code Online (Sandbox Code Playgroud)

Dan*_*rda 21

ContentPage.BackgroundImage你无法控制纵横比.而是使用Image结合AbsoluteLayout(和设置Aspect属性Image):

<?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="XilnexOTM.Views.LoginPage">

    <AbsoluteLayout VerticalOptions="FillAndExpand"
                    HorizontalOptions="FillAndExpand">

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

        <ScrollView AbsoluteLayout.LayoutFlags="All" AbsoluteLayout.LayoutBounds="0, 0, 1, 1">
            <StackLayout Orientation="Vertical">
                <Label Text="PICTURE"  />
                <Label Text="PIC 2" />

                <Entry Placeholder="Username" />
                <Entry Placeholder="Password" IsPassword="true"/>

                <Button x:Name="btn_Login"
                        Text="Login"
                        BackgroundColor="#FF0000"/>
            </StackLayout>
        </ScrollView>                   

    </AbsoluteLayout>             
</ContentPage>
Run Code Online (Sandbox Code Playgroud)

  • 或者只是使用 `Grid` 而不是 `AbsoluteLayout`。无需设置那些额外的属性 (2认同)