Is it possible to load a URL in a WebView and resize it to fit the screen? I mean I want to make the WebPage small so that the user doesn\'t need to scroll. Is this possible
I was able to contain the entire page in my view by doing the following. First set the width and height to wrap_content. Then setting the initial scale to one like this:
WebView webview = (WebView) currentActivity.findView(R.layout.web_view, R.id.webview);
webview.setInitialScale(1);
I found that I could get this to keep the width to the minimum necessary to display a readable font and then scroll along the y coordinate every time by doing the following. First set both the height and width to wrap_content. Then set the zoom density to far in your code like this:
WebView webview = (WebView) currentActivity.findView(R.layout.web_view, R.id.webview);
webview.getSettings().setDefaultZoom(ZoomDensity.FAR);
This is probably the better solution most of the time. Consider how small the font would be if you displayed the following web page in its entirety:
wb.getSettings().setLoadWithOverviewMode(true);
wb.getSettings().setUseWideViewPort(true);
As mentioned, zooming out too much is not something the user would like cause it'll reduce the legibility of the content.
I would suggest trying to set the zoom controls, however, I don't know if it'll work in 2.1.
webview.getSettings().setBuiltInZoomControls(true);
Hope this solves the problem as you now are giving user the control to change the zoom level.
I got this to work in a dialog using WRAP_CONTENT for both dimensions of the WebView, unfortunately when the web page becomes too large the webview pushes all my other widgets off the screen.
Android's layout system is pretty damn unintuitive!
webview_settings.setLoadWithOverviewMode(true);
webview_settings.setUseWideViewPort(true);
webview_settings.setBuiltInZoomControls(true);
Set the initial scale to 1. It then zooms in to fill the screen. Haven't tested how this works on really tall web sites (blog posts with lots of comments for example) but it's working on a Droid X and an HTC Aria with a standard web page.
WebView.setInitialScale(1);
I'll continue testing with different web pages but so far this is the best solution I've got for this issue.
EDIT: Tested with an obscenely long web page on both Droid X and Aria and got positive results on both. Setting the initial scale to 0 seems to turn the whole thing off resulting in initial scale being 100. I'm happy with these results, hope this helps others struggling with this issue.