title: Android Webview - Resize image if too large
body: <p>I am writing an Android application in Java, which basically functions as a forum reader for a private forum. The app displays a list of threads and once the user chooses a thread, a new Activity is opened that basically consists of a single WebView. The app downloads and parses the source (html) of the forum thread and then returns a list of 'post' items that contain just the required information (eg author, contents as html, etc). Finally, I simply build some HTML from that list of posts and display it in the WebView. </p>
  
  <p>While this is working absolutely fine, there is a problem with images: sometimes the images are very large and the user has to scroll both horizontally and vertically to see the whole image. I would like to resize these images to the width of the WebView (so that they are always fully visible), with optionally turning them into a hyperlink that opens the full size image. </p>
  
  <p>Since I am parsing the thread HTML myself, I could in theory take each img tag and add a "width=100%" attribute to it. The problem then is that small images (such as emoticons!) are also resized and blown up very large. I only want to resize images that are too large to display on the device.</p>
  
  <p>How can I achieve this? Some methods that I can think of (but not quite reach the desired solution with) are of course:</p>
  
  <ul>
  <li>Modifying the HTML of the post content before displaying it in the WebView,</li>
  <li>Changing the CSS stylesheet that the WebView uses to display the post content</li>
  <li>Adding javascript to the WebView source</li>
  </ul>
  
  <p>Basically I have complete access to the HTML, CSS and Javascript, and still I cannot figure out how to resize images that are too large (but not images that aren't too large).</p>
  
  <p>Zooming is not an issue as it is disabled for this WebView.</p>
  
  <p>Does anyone have any idea how to achieve this effect? Thanks!</p>