1

I have programmed Android since 2.1 but I really don't know how the WebView decides on the sizing of Html elements like text and images, that it is rendering. I am loading my HTML as follows:

   String displayHtml = "<html><header></header><body>"+someDivContent + "</body></html>";
   webView.loadData(displayHtml, "text/html; charset=utf-8", "UTF-8");

So everything renders fine, except for one thing. The text is so small I can barely read it. Essentially I use my fingers to zoom out and then everything looks perfect, but what I don't get is why the webview defaults to something that is so unreadable? And how can I know programatically how much zooming out I need to do? Its as if the webview does not know it can scroll or something so tries to fit everthing into the visible area of the screen and so shrinks everything. The font size is not a reasonable default, nor is the zoom. And its not just the font size, the images are also shrinked. That's my question, I will soon post the exact html data, but I get this almost everything I load from a string. I almost never get it when I load via url.

UPDATE: This question is not: How do I zoom like others answered before. The question is given dynamic HTML how do I know if I need to zoom at all? And by how much?

Thanks in advance!

  • Try mWebView.getSettings().setTextZoom(2); – tiny sunlight Mar 28 '16 at 15:57
  • why only text zoom? the photos are also shrunken? And why does it need this done? why not zoom(3) or zoom(4)? what's the reason? – FunctionallyReactive Mar 28 '16 at 16:03
  • possible duplicate - http://stackoverflow.com/questions/3796176/how-to-change-the-fontsize-in-an-android-webview – F43nd1r Mar 28 '16 at 16:10
  • No its not a duplicate because those answers are about how to increase/decrease font size. how to zoom. Important and part of the answer but this question is how do I know how much to zoom? how much to increase the font size given the html that is being displayed, screen resolution etc Is there a way to get Webview to do better default rendering? I'm dealing with dynamically generated html so its not always the same page with the same html – FunctionallyReactive Mar 28 '16 at 17:32
  • Let's vote the question up because 1. Its not a duplicate. and 2. its not that easy to answer. and 3. many people might face the same displaying dynamic html in a webview. – FunctionallyReactive Mar 29 '16 at 01:59

0 Answers0