title: GridView with square items in android with adaptive width/height
body: <p>I have a custom gridview with items like that</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:clickable="false"
  android:focusable="false"
  android:focusableInTouchMode="false"
  android:gravity="center"
  android:longClickable="false"
  android:orientation="vertical" &gt;
  
  &lt;TextView
      android:id="@+id/textView1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:clickable="false"
      android:focusable="false"
      android:focusableInTouchMode="false"
      android:longClickable="false"
      android:text="0"
      android:textSize="60sp" /&gt;
  
   &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>I want my items to be squares and I want gridview to stretch width to fill all all width of screen in portrait orientation and all height in landscape orientation.
  It should look like this
  <img src="https://i.stack.imgur.com/UskdC.jpg" alt="layout"></p>
  
  <p>Where A - is the side of a square and B is the margin width (it could be zero).
  I think that I should probably override onMeasure method, but what exactly should I do?
  Maybe anyone can help?</p>
  
  <p>EDIT
  OK, I tried to set width and height of items manually in getView method of adapter, it's better, but still it's not what I wanted. How can I get rid of that spacing between columns?</p>
  
  <p><img src="https://i.stack.imgur.com/1BXWn.png" alt="enter image description here"></p>