简体   繁体   English

Android设置WebView内容适合宽度

[英]Android set webview content fit to width

I have a webview that loads a page with an image in it. 我有一个webview可以加载带有图像的页面。 I want this webview content to fit the width of the device. 我希望此Webview内容适合设备的宽度。 The webview itself fits to screen width but its content does not. Web视图本身适合屏幕宽度,但其内容不适合屏幕宽度。 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. 在三星s5中,其内容适合宽度,但在较小宽度的设备中,它具有滚动条,并且沿左右方向滚动。 Also, if i remove setloadwithoverview, this time in smaller width devices i have a white space at the right side of the screen. 另外,如果我删除setloadwithoverview,这一次在较小宽度的设备中,我在屏幕的右侧会有一个空白。 Can anyone help me with this? 谁能帮我这个?

Thanks 谢谢

Setting image width to 100% solved the problem for me. 将图像宽度设置为100%为我解决了这个问题。

<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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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