我有一个WebView,我试图在加载页面时将其扩展到一定的百分比.该软件的iPhone版本使用HTML元标记:
<meta name="viewport" content="width=320, initial-scale=0.95, maximum-scale=2.0, user-scalable=1">
Run Code Online (Sandbox Code Playgroud)
由于Android的WebView似乎不尊重该标签,因此我使用setInitialScale()对百分比进行了硬编码.但是,WebView只是忽略了这种方法调用.不管我放在那里的数字是100%.
想法?
更新:它不能在模拟器,我的Droid(摩托罗拉)或我的G1(HTC)上运行.
有些HTC设备有问题WebView,试试这个片段吧!
import java.lang.reflect.Method;
import java.lang.reflect.InvocationTargetException;
myWebView = new WebView(this);
myWebView.getSettings().setLoadsImagesAutomatically(true);
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.getSettings().setBuiltInZoomControls(true);
myWebView.setInitialScale(100);
try {
Method m = myWebView.getClass().getMethod("setIsCacheDrawBitmap", boolean.class);
if (m != null) {
m.invoke(myWebView, false);
myWebView.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL);
}
} catch (NoSuchMethodException e) {
} catch (IllegalAccessException e) {
} catch (InvocationTargetException e) {
}
myWebView.loadUrl("http://www.stackoverflow.com");
Run Code Online (Sandbox Code Playgroud)
您是否为您的网页视图启用了缩放支持?
WebSettings webSettings = mywebView.getSettings();
webSettings.setSupportZoom(true);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16116 次 |
| 最近记录: |