我试图使用viewport meta标签来缩小我的html布局,这比设备的宽度更大。然而,viewport meta似乎被忽略了。
我使用Cordova 6.3.1 CLI和以下简单的html文件进行测试:
<html>
<head>
<meta charset="utf-8">
<!--<meta name="viewport" content="width=600" />-->
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no" />
<title>Test</title>
</head>
<body>
<!--<div style=" background:#CCC; width: 1280px; height: 800px;"></div>-->
<img src="test.jpg" width="1280" height="800"/>
</body>
</html>
配置xml如下:
<?xml version='1.0' encoding='utf-8'?>
<widget id="com.example.myapp" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<feature name="Whitelist">
<param name="android-package" value="org.apache.cordova.whitelist.WhitelistPlugin" />
<param name="onload" value="true" />
</feature>
<name>My App</name>
<description>My App Desciption</description>
<author email="contacts@myself.com" href="http://www.example.com/">
myself
</author>
<content src="index.html" />
<access origin="*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />
<allow-intent href="market:*" />
<icon density="ldpi" src="icons/drawable-ldpi/ic_launcher.png" />
<icon density="mdpi" src="icons/drawable-mdpi/ic_launcher.png" />
<icon density="hdpi" src="icons/drawable-hdpi/ic_launcher.png" />
<icon density="xhdpi" src="icons/drawable-xhdpi/ic_launcher.png" />
<icon density="xxhdpi" src="icons/drawable-xxhdpi/ic_launcher.png" />
<icon density="xxxhdpi" src="icons/drawable-xxxhdpi/ic_launcher.png" />
<preference name="loglevel" value="DEBUG" />
</widget>
但是这些都不能缩小我的html页面以适应屏幕。我在Android 4.4和5.1上测试过
是否缺少了一些设置?
<标题> 更新我已经知道我可以更新onCreate方法为跟随我的网页缩放到63%。但viewport标签仍然可以在此解决方案中不发挥任何作用-您只需删除它。
public class MainActivity extends CordovaActivity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
if (appView == null) {
init();
}
// If keepRunning
this.keepRunning = preferences.getBoolean("KeepRunning", true);
((WebView) appView.getView()).getSettings().setUseWideViewPort(true);
((WebView) appView.getView()).setInitialScale(63);
appView.loadUrlIntoView(launchUrl, true); // Set by <content src="index.html" /> in config.xml
}
}
标题>这似乎是一个已知的错误[CB-12015] -小于1.0的初始值在Android上被忽略- ASF JIRA
我决定采用上面的UPDATE部分中提到的解决方法。