我尝试使用viewport元标记缩小我的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>
Config 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%。但仍然是视口标签 在此变通办法中不起任何作用 - 您只需将其删除即可。
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
}
}
答案 0 :(得分:1)
这似乎是一个已知的错误[CB-12015] initial-scale values less than 1.0 are ignored on Android - ASF JIRA
我决定采用上面更新部分中提到的解决方法。