0

I have the following line to fit the image inside the webview to the screen width:

 String x= "<html><head><style type='text/css'>
 body{margin:auto auto;text-align:center;} 
 img{width:100%25;} 
 </style></head><body><img src=\"" + url + "\" /></body></html>";

 web_view.loadData(x, "text/html", "UTF-8");

How can I modify the code to have the image fit to the HEIGHT OF THE SCREEN instead of the width !? I want to have the effect of the image filling the entire space vertically and not necessarily horizontally (users can scroll horizontally or if the image has lower width there can be a blank space to the right). Is it possible to do this ?

Speed Demon
  • 691
  • 1
  • 9
  • 21

2 Answers2

1

You may try this :

WebSettings settings = webView.getSettings();
settings.setUseWideViewPort(true);
settings.setLoadWithOverviewMode(true);

OR

<body >
<img id="resizeImage" src="picture.png" height="100%" alt="" />
</body>
KOTIOS
  • 11,177
  • 3
  • 39
  • 66
  • is ur webview ht fixed? – KOTIOS Aug 21 '13 at 23:43
  • My WebView is filling the entire activity, I also have set those 2 properties that you mentioned (setUseWideViewPort and setLoadWithOverviewMode). I have the HTML String from above applied to the webview, it stretches the image to fit the screen width, I want to fit the screen height instead – Speed Demon Aug 21 '13 at 23:48
  • height="100% did u set this? – KOTIOS Aug 21 '13 at 23:50
  • or rather set height from this : Display display = getWindowManager().getDefaultDisplay(); int height=display.getHeight(); – KOTIOS Aug 21 '13 at 23:53
  • I can't get it to work, display.getHeight() is deprecated, it did change the height but it did not stretch it to the bottom. When I add the height='100%' attribute to the image tag in my string the image won't show up, what I get in the webview is the link to the image instead. Thank you though sir, I will eventually find a way – Speed Demon Aug 22 '13 at 00:02
1

Check my answer here, you don't always need CSS to change the appearance just change the tags in img tag.

Community
  • 1
  • 1
Ankit Bansal
  • 1,801
  • 17
  • 34