Put an image inside a webview and fit it width

android, java, webview

Solution

Using Viewport Metadata may help you to do this

The viewport is the area in which your web page is drawn. Although the viewport's visible area matches the size of the screen, the viewport has its own dimensions that determine the number of pixels available to a web page

Also try below

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

Problem

I'd like to use a WebView for displaying images potentially big (in order to seize it memory management). For the test i'm loading this code in the WebView ``` <head></head> <body> <img alt="test" src="file:///android_asset/cute-cat-sleeping.jpg"> </body> ``` The problem is that if I load it in a web "as is". The WebView only allow to zoom out until the first dimension of the image is fit in screen. In this example the image height is totally shown into the WebView and then no more zoom allowed: As you can see this mode doesn't allow a correct display of the global image despite that when the image is zoomed the behaviour in the right and bottom corners are correct as you can see here So I tried the (WebView).getSettings().setUseWideViewPort(true) and the result is that I can zoom out more than the image's width and the zoomed behaviour is not correct in the bottom-right borders: Summarizing: I'd like the max zoom out possible to be imageWidth=webview width and zoom behaviour like in the second image: Complete and/or usefull answers will be bountied EDIT: Bounty opened for Vinayak.B

Original source