title: Remove space between rows in GridView
body: <p>I know this has been asked in many different ways in StackOverflow but none of the answers seem to fit with my problem.</p>
  
  <p>As it can be seen in this picture (<a href="https://imgur.com/a/9MIlzwe" rel="nofollow noreferrer">https://imgur.com/a/9MIlzwe</a>), I get an ugly space at the bottom of the GridView because the rows don't stretch proportionally to cover all the height of the GridView. I have tried so many different codes that it is useless to write them all here. What I will do instead is to show the pieces of my code that I currently have and that are relevant for the problem.</p>
  
  <p>I first calculate the dimensions of the GridView before displaying the images inside of it. I want 3 columns and 3 rows, that's why inside setDimensions I divide by COLUMNS in both cases (because it is a constant int with value of 3):</p>
  
  <pre><code>private void setDimensions() {
  
      ViewTreeObserver vto = mGridView.getViewTreeObserver();     
  
      vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {           
          @Override
          public void onGlobalLayout() {
              mGridView.getViewTreeObserver().removeOnGlobalLayoutListener(this);         
  
              int displayWidth = mGridView.getMeasuredWidth();          
              int displayHeight = mGridView.getMeasuredHeight();
  
              mColumnWidth = displayWidth / COLUMNS;
              mColumnHeight = displayHeight / COLUMNS;
  
              display(getApplicationContext());
          }
      });
  }
  
  
  
  
  private static void display(Context context) {
      ArrayList&lt;ImageView&gt; imgs = new ArrayList&lt;&gt;();
      ImageView image;
  
  
      /*
  
      ...More code
       */
  
      mGridView.setAdapter(new CustomAdapter(imgs, mColumnWidth, mColumnHeight));
  }
  </code></pre>
  
  <p>My getView() method of the adapter class:</p>
  
  <pre><code>@Override
  public View getView(int position, View convertView, ViewGroup parent) {            
  
      ImageView imageView;
  
      if (convertView == null) {
          imageView = imgs.get(position);
      } else {
          imageView = (ImageView) convertView;
      }
  
  
      android.widget.AbsListView.LayoutParams params = new android.widget.AbsListView.LayoutParams(mColumnWidth, AbsListView.LayoutParams.WRAP_CONTENT);        
      imageView.setLayoutParams(params);
  
  
      return imageView;
  }
  </code></pre>
  
  <p>One of the solutions I've come across many times when searching for it is to inflate a layout for the view (in this case, for the ImageView) and then use <code>android:adjustViewBounds="true"</code> for the ImageView, but this has no effect.</p>
  
  <p>As required by Ferran, this is the code I try inflating the ImageView:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;ImageView xmlns:android="http://schemas.android.com/apk/res/android"
  
      android:layout_width="50dp"
      android:layout_height="50dp"
      android:layout_centerInParent="true"
      android:scaleType="fitXY"
      android:adjustViewBounds="true"
      /&gt;
  </code></pre>
  
  <p>The code above would be in combination with this:</p>
  
  <pre><code>@Override
  public View getView(int position, View convertView, ViewGroup parent) {
  
      ImageView imageView;
  
      if (convertView == null) {
  
          LayoutInflater layoutInflater = LayoutInflater.from(mContext);
          imageView = (ImageView) layoutInflater.inflate(R.layout.image_item, parent, false);
  
      } else {
          imageView = (ImageView) convertView;
      }
  
      imageView.setMinimumHeight(mColumnHeight/3);
      imageView.setMinimumWidth(mColumnWidth/3);
  
  
      return imageView;
  }
  </code></pre>
  
  <p>And the result would be a white screen of death: <a href="https://imgur.com/a/GJXRsxV" rel="nofollow noreferrer">https://imgur.com/a/GJXRsxV</a></p>