安卓4.1视窗缩放(setInitialScale,元初始规模不工作) [英] Android 4.1 viewport scaling ( setInitialScale, meta initial-scale not working)

查看:266
本文介绍了安卓4.1视窗缩放(setInitialScale,元初始规模不工作)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有数百个职位的跨SO和有关试图修复Android中视口中缩放互联网的休息,现在我相当肯定,你就不能设置初始规模在Android上4.1的WebView。

There are hundreds of posts across SO and the rest of the internet about trying to fix viewport scaling in Android, and I'm now fairly certain that you just cannot set the initial-scale in a webview on Android 4.1.

我要建一个科尔多瓦(PhoneGap的)应用程序,我已经得到了在iPhone 3GS,4S和5和iPad 2的比例精美的每一件事情,运行iOS7和3GS上的iOS6​​

I'm building a Cordova (Phonegap) app, and I've got every thing scaled nicely on the iPhone 3GS, 4S and 5 and an iPad 2, running iOS7 and the 3GS on iOS6

我也得到了用户界面缩放到适合的摩托G,LG的Nexus 5,谷歌Nexus 5和三星Galaxy S4,所有运行Android 4.4

I've also got the UI scaled to fit on the Moto G, LG Nexus 5, Google Nexus 5 and Samsung Galaxy S4, all running Android 4.4

不过,在三星Galaxy S2和S3迷你运行的是Android 4.1,我不能设置初始规模。

But on a Samsung Galaxy S2 and S3 Mini running Android 4.1, I cannot set the initial-scale.

在HTML视窗meta标签不上4.1或4.4(作品在Chrome,而不是在web视图或默认的浏览器)的工作:

The HTML viewport meta tag doesn't work on 4.1 or 4.4 (works in Chrome, not in the WebView or default browser):

<meta name="viewport" content="user-scalable=no, initial-scale=0.5, width=device-width, height=device-height, target-densitydpi=device-dpi" />

我敲了一个绝对的基本科尔多瓦项目从CLI,科尔多瓦创建basicProject ,如果我想补充一些Java的onCreate方法中的主要活动具体而言,在 setInitialScale 方法:

I've knocked up an absolutely basic Cordova project from the cli, cordova create basicProject, and if I add some Java to the onCreate method in the main Activity, specifically the setInitialScale method:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    super.init();
    // Set by <content src="index.html" /> in config.xml
    super.loadUrl(Config.getStartUrl());
    //super.loadUrl("file:///android_asset/www/index.html");

    this.appView.setInitialScale( 50  );

}

然后我得到的摩托G于4.4缩放预期:

Then I get the Moto G on 4.4 scaling as expected:

但究竟在Galaxy S2运行在同一个项目,不会被缩放。

But exactly the same project running on the Galaxy S2, does not get scaled.

我有限的测试上三星设备4.1,或者4.4各种设备,因此,如果任何人都可以测试4.2或4.3,或任何人在同样的事情上4.1不与三星这会有所帮助。

I'm limited to testing on Samsung devices with 4.1, or a range of devices on 4.4, so if anyone can test the same thing on 4.2 or 4.3, or anyone on 4.1 not with a Samsung that'd be helpful.

有谁知道怎么弄的Andr​​oid 4.1服从 setInitialScale()

Does anyone know how to get Android 4.1 to obey setInitialScale()

推荐答案

您应该能够一些JavaScript添加到您的网页,这将扩大拾起你的web视图时的内容。这里是使得内容适合于屏幕的可用宽度,将缩放您的HTML内容的示例:

You should be able to add some javascript to your webpages that will scale the content when picked up by your webview. Here is an example that will scale your html content so that the content fits to the available width of the screen:

function customScaleThisScreen() 
    var contentWidth = document.body.scrollWidth, 
        windowWidth = window.innerWidth, 
        newScale = windowWidth / contentWidth;
    document.body.style.zoom = newScale;
}

这将工作在较旧的(pre 4.2)和新的铬基(4.2+)webviews。

This will work on older (pre 4.2) and newer chromium-based (4.2+) webviews.

HTHS

这篇关于安卓4.1视窗缩放(setInitialScale,元初始规模不工作)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆