开发者

Android WebView overview mode loads image zoomed in

I'm using following code to display an image in a WebView:

    final WebView web = (WebView) findViewById(R.id.webView);
    web.getSettings().setJavaScriptCanOpenWindowsAutomatically(false);
    web.getSettings().setPluginsEnabled(false);
    web.getSettings().setSupportMultipleWindows(false);
    web.getSettings().setSavePassword(false);
  开发者_如何转开发  web.getSettings().setBuiltInZoomControls(true);
    web.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
    web.getSettings().setUseWideViewPort(true);
    web.getSettings().setLoadWithOverviewMode(true);
    String url = extras.getString("url");
    String x = "<html><head><meta name=\"viewport\" content=\"width=device-width\"/><style type=\"text/css\">html, body {margin: 0;padding: 0;} img {border: none;}</style><head><body style=\"background: black;\"><table><tr><td align=\"center\"><img src=\"" + url + "\" /></td></tr></table></body></html>";
    web.loadDataWithBaseURL(null, x, "text/html", "utf-8", null);

According to the manual, it should be started in overview mode, so it should be maximally zoomed out (and that's what I want to do). Unfortunately, the image is zoomed in. How can I fix it?


I think what is happening here is that the width=device-width says the viewport should be 480 pixels wide (or whatever the device is). So an image that's wider than that will be partly off the screen and need to be scrolled.

If you want the page to open in overview mode, I think you should set that when creating the WebView and not specify any viewport.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜