title: How can i center the content of a WebView?
body: <p>A part of my app loads an image into a WebView from a URL.
  Using the following settings for the WebView:</p>
  
  <pre><code>myWebView.getSettings().setBuiltInZoomControls(true);
  myWebView.getSettings().setDisplayZoomControls(false);
  myWebView.getSettings().setLoadWithOverviewMode(true);
  myWebView.getSettings().setUseWideViewPort(true);
  </code></pre>
  
  <p>Relevant part from the layout XML:</p>
  
  <pre><code>&lt;RelativeLayout
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:background="@android:color/transparent" &gt;
  
      &lt;WebView
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:scrollbars="none" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>The problem with this, if the image if smaller in height than the screen, it appears aligned to the top of the WebView.</p>
  
  <p>Is it possible to align it to the center?</p>
  
  <p>I tried the following, but it just doesn't work all the time, no idea why.</p>
  
  <pre><code>&lt;RelativeLayout
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:background="@android:color/transparent" &gt;
  
      &lt;WebView
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_centerInParent="true"
          android:scrollbars="none" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>Any help would be appreciated.</p>
  
  <p>Thanks in advance.</p>
  
  <p>edit:
  Tried the following with CSS, still doesn't work (the image is displayed, but not centered vertically).</p>
  
  <pre><code>myWebView.loadDataWithBaseURL(null, "&lt;html&gt;&lt;head&gt;&lt;style&gt;img {margin-top:auto;margin-bottom:auto}&lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;img src=\"" + url + "\"&gt;&lt;/body&gt;&lt;/html&gt;", "html/css", "utf-8", null);
  </code></pre>
  
  <p>edit2:
  Bojan Kseneman's solution is working. I was using</p>
  
  <pre><code>android:configChanges="orientation|keyboardHidden|screenSize
  </code></pre>
  
  <p>that's why it seemed to be wrong at first. Removed this line from my <code>Manifest.xml</code> fixed the problems (handling <code>onSaveInstanceState</code> is of course necessary in this case).</p>