简体   繁体   中英

Fit image to screen height - WebView in Android

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 ?

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>

在这里查看我的答案,你并不总是需要CSS来改变外观只需更改img标签中的标签。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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