简体   繁体   中英

Android set webview content fit to width

I have a webview that loads a page with an image in it. I want this webview content to fit the width of the device. The webview itself fits to screen width but its content does not. Here is what i do:

bannerWV = new WebView(getContext());
bannerWV.setWebViewClient(new mWebViewClient());
bannerWV.setWebChromeClient(new WebChromeClient());
bannerWV.getSettings().setJavaScriptEnabled(true);
bannerWV.getSettings().setLoadWithOverviewMode(true);
bannerWV.getSettings().setUseWideViewPort(true);

bannerWV.loadUrl("http://...");
feedsLV.addHeaderView(bannerWV);

In samsung galaxy s5, its content fits to width but in smaller width devices, it has a scroll and scrolls in the left-right direction. Also, if i remove setloadwithoverview, this time in smaller width devices i have a white space at the right side of the screen. Can anyone help me with this?

Thanks

Setting image width to 100% solved the problem for me.

<img alt="..." rev="..." src="..." border="0" width="100%">

And for the white space at the right side of the screen, the following worked:

webview.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM