Responsive website show on Web view out of mobile

2020-06-01 06:25发布

I am using webview to load the responsive website but it shows the width outside to the mobile size.

I open the link in a mobile Chrome browser and it looks good...

I mean to say the width does not fit to screen size of mobile; it shows out of width.

I am also using these... for <viewport> tag for controlling its presentation.

    WebSettings settings = webview.getSettings();
    settings.setJavaScriptEnabled(true);

    settings.setUseWideViewPort(true);
    settings.setLoadWithOverviewMode(true); 

Also I am using setInitialScale for webview render properly.

    webview.setInitialScale((int) 1.0);

but I am getting the website load not responsive as according to size... it shows the width is outside to screen size... which comes with scroll

Application works fine in Lollipop, Marshmallow etc. But does not work in Jellybean etc. But the Link works well with latest chrome in all devices but does not work in webview.

I also set this....

 <meta name="viewport" content="width=device-width, initial-scale=1">

Screenshot

enter image description here

7条回答
迷人小祖宗
2楼-- · 2020-06-01 07:01

is your web view layout_width="match_parent"?

you can also use:`

setting.setBuiltInZoomControls(true);
webView.setWebViewClient(new WebViewClient());
webView.setWebChromeClient(new WebChromeClient());

before:

settings.setUseWideViewPort(true);
settings.setLoadWithOverviewMode(true);
查看更多
我想做一个坏孩纸
3楼-- · 2020-06-01 07:08

try this one hope it will help you

    String link = "";// global variable
    Resources res;// global variable
         //in onCreate
    res = ctx.getResources();
    link = url;

    faqwebview.getSettings().setJavaScriptEnabled(true);
    faqwebview.setWebViewClient(new WebViewClient() {

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            // TODO Auto-generated method stub
            super.onPageStarted(view, url, favicon);
            if (!loading) {
                loading=true;
                Utils.ShowMyprogress(this, "Fetching data...");
            }
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            // TODO Auto-generated method stub
            super.onPageFinished(view, url);
            Utils.DismissMyprogress();
            loading=false;
        }

        @Override
        public void onReceivedError(WebView view, int errorCode,
                String description, String failingUrl) {
            // TODO Auto-generated method stub
            super.onReceivedError(view, errorCode, description, failingUrl);
            Utils.DismissMyprogress();
            Utils.showToast(this, "error in load page==" + description);
        }
    });



    faqwebview.loadUrl((link == null || link.isEmpty()) ? res
            .getString(R.string.app_baseurl) : link);
查看更多
可以哭但决不认输i
4楼-- · 2020-06-01 07:09
webView = (WebView) findViewById(R.id.noticiasWebView);
webView.setInitialScale(1);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setUseWideViewPort(true);
webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
webView.setScrollbarFadingEnabled(false);
webView.loadUrl("http://www.resource.com.br/");
查看更多
Viruses.
5楼-- · 2020-06-01 07:12

Try This:

WebView browser = (WebView) findViewById(R.id.webview);
browser.getSettings().setLoadWithOverviewMode(true);
browser.getSettings().setUseWideViewPort(true);
查看更多
虎瘦雄心在
6楼-- · 2020-06-01 07:15

Enabling DOM should help I guess

webView.getSettings().setDomStorageEnabled(true);
查看更多
▲ chillily
7楼-- · 2020-06-01 07:17
web.setInitialScale(1);
    web.getSettings().setLoadWithOverviewMode(true);
    web.getSettings().setUseWideViewPort(true);

try this code may be solve your issue.

查看更多
登录 后发表回答