2

I'm looking for a way to have images appear in a WebView that initially fits the screen, instead of showing the actual size. Is there a way to do this?

How is it different if:

1) I open an html file with an img tag to the image

2) I open the image file directly

Thanks for any assistance.

Gibson
  • 780
  • 3
  • 14
  • 33
  • i have tried solutions presented here https://stackoverflow.com/questions/3099344/can-androids-webview-automatically-resize-huge-images/20192803#20192803 and it worked fine. – Desire Aheza Jun 12 '15 at 06:02

3 Answers3

14

I ended up using:

     mWebView.getSettings().setLoadWithOverviewMode(true);
     mWebView.getSettings().setUseWideViewPort(true);

To make the contents of the page fit to the WebView.

Gibson
  • 780
  • 3
  • 14
  • 33
0

You can use Webview's LayoutAlgorithm. But this will resize only those images with Width greater than the width of the device. This won't help you with images smaller than the screen.

Link: Can Android's WebView automatically resize huge images?


Another Solution is using a Javascript or an External Library like HTML Cleaner to remove the

<img> size attributes and then change their size via code and getWidth().

Community
  • 1
  • 1
Sheharyar
  • 73,588
  • 21
  • 168
  • 215
0

If I understand the question, you have an image on a web page that has dimensions X x Y and when you load the webpage into a WebView you want it to take up the dimensions of the android device (X1 x Y1). To do this pass a querystring to the url which renders the height and the width of the image at 100%. Also have the layout_width and layout_height of the webview set to the appropriate values.

If you load the image directly into the WebView, you can set the height and width of the image

Herb
  • 345
  • 1
  • 17