【问题标题】:Titanium webview rendering incorrectly on Android 5Titanium webview 在 Android 5 上渲染不正确
【发布时间】:2015-04-18 17:18:41
【问题描述】:

我的 android 手机(Samsung Galaxy S5、AT&T)刚刚从 Android 4.4 更新到 5.0,现在无法在 Titanium 中渲染 webviews。我有一个在 Android 4.4 上运行良好的已发布应用程序,现在在 5.0 中无法正确呈现(同一部手机,没有应用程序代码更改)。具体来说,似乎该窗口的默认画布自动具有巨大的高度和宽度(至少是屏幕大小的 4 倍),并且将 div 换行和格式化为绝对位置不起作用。以前,画布是屏幕的宽度,因此会发生自动换行,而窗口的高度是窗口中内容的高度。我用下面的合金代码在我的手机上重现了错误:

<Alloy>
<Window title="Test">
<WebView id="web1" html="<html><head></head><body><p>This is a long paragraph that should have word wrap once it reaches the right side of the screen, but unfortunately the new version of Android seems to be preventing this behavior, which is peculiar, as issues did not arise with prior versions of Android, as far as I can tell.</p></body</html>" class="webclass" backgroundColor="transparent" />
</Window>
</Alloy>

任何帮助将不胜感激。

【问题讨论】:

    标签: webview titanium


    【解决方案1】:

    我有同样的问题,我搜索了很多,我发现它取决于设备上正在运行的操作系统。

    尝试将此代码添加到js文件中,它不会解决问题,但它应该进行自动换行和放大。

    var htmlText = "<p>This is a long paragraph that should have word wrap once it reaches the right side of the screen, but unfortunately the new version of Android seems to be preventing this behavior, which is peculiar, as issues did not arise with prior versions of Android, as far as I can tell.</p>"
    
    if(OS_ANDROID) htmlText = '<html><body><div style="width:' + 
            (Titanium.Platform.displayCaps.platformWidth - 20) + 'px; height:auto;">' + 
            htmlText + '</div></body></html>';
    $.webView.html = htmlText;
    

    【讨论】:

    • 感谢您的建议,但由于某种原因,这对我也不起作用。我根本没有收到任何错误代码......由于某种原因,它没有正确换行,即使使用这个 CSS 宽度(文本比随机换行前的屏幕宽约 2.5 倍)。
    【解决方案2】:

    在每个 HTML 文件中添加以下代码似乎可以在各种 Android 版本中创建一致的 HTML 渲染,并确保屏幕宽度合适:

    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-05-28
      • 1970-01-01
      • 2023-03-15
      • 1970-01-01
      • 1970-01-01
      • 2011-03-19
      • 1970-01-01
      • 2013-12-27
      相关资源
      最近更新 更多