Android 5上的Titanium webview呈现不正确

时间:2015-04-18 17:18:41

标签: webview titanium

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

<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>

任何帮助都将不胜感激。

2 个答案:

答案 0 :(得分:0)

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

尝试在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;

答案 1 :(得分:0)

将以下代码添加到每个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">