Issue
What I have: I'm loading image from a URL. I simply do (WebView).loadUrl(imageurl, extraheaders)
What I get: Image is not showing at full width of the WebView, it has blank space all around (like if you open a little iamge in your desktop browser)
What i tried: Setting LayoutAlgorithm to SINGLE_COLUMN. Works perfect, but zooming doesn't work. (I have it enabled in the WebView.getSettings()
Dont know why. Setting setUseWideViewPort(true);
load image without any blanks space, but it is fully zoomed in.
Solution
I had the same issue and doing this worked just fine:
Display display = getWindowManager().getDefaultDisplay();
int width = display.getWidth();
String data = "<html><head><title>Example</title><meta name=\"viewport\"\"content=\"width="+width+", initial-scale=0.65 \" /></head>";
data = data + "<body><center><img width=\""+width+"\" src=\""+url+"\" /></center></body></html>";
webView.loadData(data, "text/html", null);
Edit: As this remained as the accepted answer, here is a better solution (all credit to Tony below):
WebView content = (WebView) findViewById(R.id.webView1);
content.loadDataWithBaseURL(null, "<style>img{display: inline;height: auto;max-width: 100%;}</style>" + post.getContent(), "text/html", "UTF-8", null);
Answered By - Sebastian Breit
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.