Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/313.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 缩小WebView初始比例_Java_Android_Webview - Fatal编程技术网

Java 缩小WebView初始比例

Java 缩小WebView初始比例,java,android,webview,Java,Android,Webview,我想缩小我的WebView初始比例,如以下视口配置: <meta name="viewport" content="width=device-width, initial-scale=0.93, maximum-scale=0.93, user-scalable=no" /> 有没有办法做到这一点?当您使用user scalable=no时,缩放功能将被禁用。如果您无法从网页源更改此内容,唯一可能的解决方案是在页面加载完成时使用Javascr

我想缩小我的
WebView
初始比例,如以下视口配置:

<meta name="viewport" content="width=device-width, initial-scale=0.93, maximum-scale=0.93, user-scalable=no" />

有没有办法做到这一点?

当您使用user scalable=no时,缩放功能将被禁用。如果您无法从网页源更改此内容,唯一可能的解决方案是在页面加载完成时使用Javascript更改Viewport Content属性。要允许此操作,必须将setJavaScriptEnabled设置为true


作为替代,我们可以在这里尝试CSS

添加要缩小的类&完成或不再需要缩小后删除该类

。缩小比例{
变换:比例(0.93);
}

我被缩小到93/100

您正在使用
用户可伸缩=否“
取消放大/缩小。不用它试试。@tukan无法更改此设置,因为我没有访问源网页的权限,但是在ios safari上使用
initial scale=0.93
param时,此设置效果很好!它之所以能工作,可能是因为它忽略了
用户可伸缩性
。如果您没有源代码,那么我就没有主意了。我会尝试
zoomBy(93)
setLayoutParams(新视图组。LayoutParams((int)(宽度/100F*93),(int)(高度/100F*93))
    mWebView.getSettings().setLoadWithOverviewMode(true);
    mWebView.getSettings().setUseWideViewPort(true);
    mWebView.setInitialScale(93);
webView = (WebView) findViewById(R.id.webview);
webView.getSettings().setUseWideViewPort(true);
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient(){
 @Override
 public void onPageFinished(WebView view, String url) {
    super.onPageFinished(view, url);
    //Option 1: change the viewport content after the page is finished loaded and set initial-scale=0.93 and user-scalable=yes
    view.loadUrl("javascript:document.getElementsByName('viewport')[0].setAttribute('content', 'width=device-width, initial-scale=0.93, maximum-scale=0.93, user-scalable=yes');");

    //Option 2: change the body zoom style to the initial value you want eg: 0.93 (93%)
    //view.loadUrl("javascript:document.body.style.zoom = "+String.valueOf(0.93)+";");
  }
 });
//load the url
webView.loadUrl(url);