title: Android picture with correct aspect ratio and border
body: <p>I want to have fixed size box 120x180 dp that contains a picture with correct aspect ratio and a border painted around it.</p>
  
  <p>XML:</p>
  
  <pre><code>&lt;android.support.constraint.ConstraintLayout
  android:layout_width="120dp"
  android:layout_height="180dp"
  app:layout_gravity="center"&gt;
  
  &lt;ImageView
      android:id="@+id/picture"
      android:layout_width="0dp"
      android:layout_height="0dp"
      android:background="@drawable/game_border"
      app:srcCompat="@drawable/pic_lion"
      android:scaleType="centerInside" /&gt;
  </code></pre>
  
  <p>Game_border layout:</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="#55111111" /&gt;
          &lt;padding
              android:bottom="4dp"
              android:left="4dp"
              android:right="4dp"
              android:top="4dp" /&gt;
  
          &lt;corners android:radius="6dp" /&gt;
      &lt;/shape&gt;
  &lt;/item&gt;
  &lt;/layer-list&gt;
  </code></pre>
  
  <p>This <code>scaleType</code> setting works fine because it fill complete tile inner and background is not overriden. But to demonstrate incorrect aspect ratio I have increased top margin. See picture below. I tried remaining values but they either paint over the border or do not fill complete inner part. </p>
  
  <p>How can I have the tile that has the border around a part of the picture with the right aspect ratio? The picture can be cut. I think that this technique is called center crop. I found it in the Picasso library.</p>
  
  <p><a href="https://i.stack.imgur.com/A6qjF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/A6qjF.png" alt="enter image description here"></a></p>
  
  <p>FitXY deforms picture:</p>
  
  <p><a href="https://i.stack.imgur.com/WCkHY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WCkHY.png" alt="Bad aspect"></a></p>
  
  <p>Manually painted picture when I cropped picture while preserving aspect ratio. Sorry, it looks ugly but bounty ends very soon.</p>
  
  <p><a href="https://i.stack.imgur.com/qln9d.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qln9d.png" alt="enter image description here"></a></p>
  
  <p>Bjorn's answer:</p>
  
  <p><a href="https://i.stack.imgur.com/XcRMe.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XcRMe.png" alt="enter image description here"></a></p>
  
  <p>Rahul answer does not have bottom border</p>
  
  <p><a href="https://i.stack.imgur.com/I5lrd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/I5lrd.png" alt="enter image description here"></a></p>