title: How to force GridView to generate square cells in Android
body: <p>How can I force an android GridView to generate square cells (Cell's height equal to cell's width)
  GridView has 10*9 cells and the app must support multiple screens !</p>
  
  <p>I used a Linear Layout:</p>
  
  <p><strong>row_grid.xml</strong></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:padding="0dp" &gt;
  
          &lt;ImageView
              android:id="@+id/item_image"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:scaleType="fitXY"
              android:src="@drawable/ic_launcher" &gt;
          &lt;/ImageView&gt;
  
      &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>and GridView:
  <strong>activity_main.xml</strong></p>
  
  <pre><code>&lt;RelativeLayout 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:background="@drawable/katy" &gt;
  
      &lt;GridView
          android:id="@+id/gridView1"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:horizontalSpacing="0dp"
          android:numColumns="4"
          android:stretchMode="columnWidth"
          android:verticalSpacing="0dp" &gt;
      &lt;/GridView&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>Each cell of GridView contains a image that has same width and height.
  images are larger than cells and must stretch to fit in cells.
  <img src="https://i.stack.imgur.com/YnSwU.png" alt="enter image description here"></p>