title: Center bitmap verticaly and horizontaly while preserving it's aspect ratio
body: <p>I am working on a splashcreen drawable that has black background and logo image in the center. At present that file looks like this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  
  &lt;layer-list xmlns:android="http://schemas.android.com/apk/res/android" android:opacity="opaque"&gt;
      &lt;!-- the background color. it can be a system color or a custom one defined in colors.xml --&gt;
      &lt;item android:drawable="@android:color/black" /&gt;
  
      &lt;item&gt;
          &lt;!-- the app logo, centered horizontally and vertically --&gt;
          &lt;bitmap
              android:src="@drawable/splash"
              android:gravity="center"
              /&gt;
      &lt;/item&gt;
  &lt;/layer-list&gt;
  </code></pre>
  
  <p>However there is an issue that is demonstrated in image below. Image is bigger than device width and get's cut off. Ideally I'd like to preserve this image's aspect ratio but fit it in the device view while not streching it in any way (preserving its aspect ratio).</p>
  
  <p>Original image (that white text) has dimensions of 930x473 px.</p>
  
  <p><a href="https://i.stack.imgur.com/pR2vZ.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pR2vZ.jpg" alt="enter image description here"></a></p>