title: Equivalent of ImageView scaleType 'centerCrop' to bitmap drawable gravity
body: <p>I have created an activity with a header image. This header image is originally created int the Activity's layout xml using an ImageView where the scaleType is set to centerCrop. This does what I want, it centers the image, clipping it left and right in portrait mode, showing all in landscape mode.</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:paddingTop="30dp"
      android:paddingBottom="6dp"
      android:paddingLeft="6dp"
      android:paddingRight="6dp"
      android:background="#919EAC"
      android:orientation="vertical" &gt;
  
  &lt;ImageView
      android:id="@+id/header_image"
      android:layout_width="match_parent"
      android:layout_height="120dp"
      android:contentDescription="@string/header_description"
      android:scaleType="centerCrop"
      android:src="@drawable/header" /&gt;
  
      .... &lt;other views&gt; ...
  </code></pre>
  
  <p>I'd like to replace this with a background drawable so that I can use the header image space to display data, and it saves me repeating the same layout in the different activities.</p>
  
  <p>For this reason I have created a drawable that I can refer to in the android:background attribute:</p>
  
  <pre><code>    &lt;layer-list xmlns:android="http://schemas.android.com/apk/res/android" &gt;
          &lt;item&gt;
              &lt;shape android:shape="rectangle" &gt;
                  &lt;solid android:color="#919EAC" /&gt;
              &lt;/shape&gt;
          &lt;/item&gt;
          &lt;item&gt;
              &lt;bitmap 
                  android:antialias="true"
                  android:gravity="top|center_horizontal"
                  android:src="@drawable/header" /&gt;
          &lt;/item&gt;
      &lt;/layer-list&gt;
  </code></pre>
  
  <p>This drawable defines the colored background that otherwise the layout would define and it defines a header image that otherwise would be included in the layout as an ImageView.</p>
  
  <p>However now my image is scaled, while I would like it to be cropped.</p>
  
  <p>Checking the Android documentation I tried other gravity modes such as </p>
  
  <pre><code>    android:gravity="top|clip_horizontal"
  </code></pre>
  
  <p>But it still seems to display/scale differently than the image view.</p>
  
  <p>What would be the correct definition of the background drawable?</p>