Alex Rivera | Logout

Can Android's WebView automatically resize huge images?

Asked 2010-06-23T06:23:48.730
31

In some web browsers, huge images are automatically resized to fit the screen.

Is it possible to do the same in an Android WebView?

The web page just contains the image, maybe adding some JavaScript could do the trick?
Anybody has already done this?

Note: I don't know the size of the image in advance.

Edit
Report

1 Answer

2

If your WebView width is fill_parent then you can use this code:

Display display=getWindowManager().getDefaultDisplay();
int width=display.getWidth();
String data="<img src='http://example.com/image.jpg' style='width:"+width+"px' />";
webView.loadData(data, "text/html", "utf-8");

And zoom still working!

Same method if height is fill_parent.

answered 2012-06-14T13:34:33.197

Your Answer