title: Android, RecyclerView with GridLayoutManager and ImageView as cell content does not fit the vertical space
body: <p>I'm trying to implement a simple grid of images.</p>
  <p>Each image is the same size, the problem is that if I scale down the images (for example if I set a spanCount so that the gridlayout has to resize images to fit them) the &quot;virtual-cell&quot; that contains the image does not adapt to image size.</p>
  <p>Here you can see the differences between spanCount=3 and spanCount=4.</p>
  <p><a href="https://i.stack.imgur.com/g7Pmy.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/g7Pmy.png" alt="enter image description here" /></a><a href="https://i.stack.imgur.com/EEnZb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EEnZb.png" alt="enter image description here" /></a></p>
  <p>If I use <code>fitXY</code> for the imageView this is the result, so the grid layout manager reduces the cell width but does not fit the cell height.</p>
  <p><a href="https://i.stack.imgur.com/YmJwD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YmJwD.png" alt="enter image description here" /></a></p>
  <p>My grid layout xml:</p>
  <pre><code>       &lt;androidx.recyclerview.widget.RecyclerView
              android:id=&quot;@+id/grid&quot;
              android:layout_width=&quot;wrap_content&quot;
              android:layout_height=&quot;wrap_content&quot;
              app:layoutManager=&quot;androidx.recyclerview.widget.GridLayoutManager&quot;
              app:spanCount=&quot;4&quot;
              tools:itemCount=&quot;30&quot;
              tools:listitem=&quot;@layout/image_item&quot; /&gt;
  </code></pre>
  <p>And image_item.xml</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;ImageView xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
      xmlns:tools=&quot;http://schemas.android.com/tools&quot;
      android:id=&quot;@+id/imageView&quot;
      android:layout_width=&quot;wrap_content&quot;
      android:layout_height=&quot;wrap_content&quot;
      android:scaleType=&quot;fitCenter&quot;
      tools:srcCompat=&quot;@tools:sample/avatars&quot; /&gt;
  </code></pre>
  <p>My targets:</p>
  <ul>
  <li>STEP 1: remove the gap between columns</li>
  <li>STEP 2: resize the images so that they always fit the horizontal space (in this example with spanCount = 3 a small space is visible on the right)</li>
  </ul>
  <p>To be more clear, I need to remove the space marked red.</p>
  <p><a href="https://i.stack.imgur.com/ZQpsu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZQpsu.png" alt="enter image description here" /></a></p>