windows-phone-7 - PhoneGap 应用程序中的 Windows Phone 屏幕高度不是 100%

标签 windows-phone-7 windows-phone-8 cordova

我正在使用 PhoneGap/Cordova 开发一个 Windows Phone 应用程序(不过,我相信我遇到的问题使得它与 PhoneGap 无关)。
无论我做什么,我的 html 页面的标签都不会垂直填充屏幕。
在 Chrome 甚至 IE 中运行页面时看起来不错
这是它在模拟器上的样子,我在 .css 中的标签上添加了一个蓝色边框,以强调正在发生的事情:

enter image description here

这是 body 的CSS:

  body{
    border: 1px blue solid;

}

html, body{
    height:100%;
    min-height:100%
}

这是页脚css:
div.navbar_table_container {
    width: 100%;
    height: auto;   
    position: absolute;
    bottom: 0;
    background-image:url(images/bottom-nav.png);
    background-size:100% 100%;
    background-repeat:no-repeat;
    text-align: center;
}

而且,因为它可能很重要,这里是 xaml 文件:
<phone:PhoneApplicationPage 
    x:Class="CordovaWP8_2_7_01.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d" FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    Background="White"
    SupportedOrientations="Portrait" Orientation="Portrait"
    shell:SystemTray.IsVisible="True" d:DesignHeight="820" d:DesignWidth="480" 
    xmlns:my="clr-namespace:WPCordovaClassLib">
    <Grid x:Name="LayoutRoot" Background="Transparent" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <my:CordovaView HorizontalAlignment="Stretch" 
                   Margin="0,0,0,0"  
                   x:Name="CordovaView" 
                   VerticalAlignment="Stretch" />
        <Image Source="SplashScreenImage.jpg"
          x:Name="SplashImage"
          VerticalAlignment="Stretch"
          HorizontalAlignment="Stretch">
            <Image.Projection>
                <PlaneProjection x:Name="SplashProjector"  CenterOfRotationX="0"/>
            </Image.Projection>
        </Image>
    </Grid>

</phone:PhoneApplicationPage>

一个重要的注意事项是它在 Chrome、IE 中以及当我将它作为 Android 应用程序运行时以我想要的方式工作。

我能找到的最接近我的问题是
Phonegap Windows Phone gap space bottom
但那里的答案对我没有帮助。

我最近注意到,当我从 Web 服务器上运行相同的代码并在 Windows Phone 上使用 IE 访问它时,它看起来很好。但是,我确实注意到,每当手机上显示警报时,IE 的地址栏就会消失,并留下与 native 应用程序始终显示的从 Web 内容底部到手机底部完全相同的间隙。

所以,这让我相信,即使它是一个“应用程序”,如果它运行 html 和 javascript,手机也会为地址栏留出空间,即使它从未使用过。

任何帮助或见解将不胜感激。

最佳答案

我尝试在视口(viewport)元标记中使用设备高度,但是我了解到 IE 不支持该标记。然后在我 100,000 次谷歌搜索后,我找到了 this page .

将此添加到我的 CSS 后:

@viewport{height:device-height}
@viewport{width:device-width}
@-ms-viewport{height:device-height}
@-ms-viewport{width:device-width}

并将其添加到命中我所有页面的 JavaScript 文件中:
if (navigator.userAgent.match(/IEMobile\/10\.0/)) {
    var msViewportStyle = document.createElement("style");

    msViewportStyle.appendChild(
        document.createTextNode(
            "@-ms-viewport{width:auto!important}"
        )
    );

    msViewportStyle.appendChild(
        document.createTextNode(
            "@-ms-viewport{height:device-height!important}"
        )
    );

    document.getElementsByTagName("head")[0].appendChild(msViewportStyle);
}

然后我 100% 的高度开始按照我的预期行事。

关于windows-phone-7 - PhoneGap 应用程序中的 Windows Phone 屏幕高度不是 100%,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16705223/

相关文章:

c# - 从 Windows Phone 8.1 中的任务调用主线程

xaml - 如何在 Windows Phone 上将方形图像制作为圆形图像

javascript - 用于访问下一个 html 页面的静态 4 位密码

android - 制作我的 Ionic AngularJS 程序的 iOS 应用程序

windows-phone-7 - 什么时候保存应用程序的状态以进行逻辑删除?

windows-phone-7 - Windows Phone 7 是否有类似 iPhone 中的 UITableview 的组件?

c# - ♥ 字符在 Glyphs 中显示不正确

c# - 序列化中的 System.OverflowException

javascript - 在 Phonegap 应用程序中使用 JavaScript 将表单数据保存到本地存储

windows-phone-7 - 如何在Windows Phone 7.5中关闭后台音频代理?