title: How to center GridView correctly?
body: <p>I have been trying and trying and no such luck. I have lucked at all other answers on here as well related to centering <code>GridView</code> and also no luck. This is my <code>GridView</code> xml:</p>
  
  <pre><code>&lt;GridView
          android:id="@+id/calendar_grid"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:numColumns="7"
          android:columnWidth="40dp"
          android:verticalSpacing="1dp"
          android:horizontalSpacing="1dp"
          android:paddingTop="2dp"
          android:stretchMode="columnWidth"
          android:layout_gravity="right"
          android:gravity="right"
          android:background="#696969" &gt;&lt;/GridView&gt;
  </code></pre>
  
  <p>I have tried every combination I can think of, but not much has worked. At least its not consistent between devices. This is an image of what it always does.</p>
  
  <p><img src="https://i.stack.imgur.com/WM6AD.png" alt="enter image description here"></p>
  
  <p>As you can see on the right side of the GridView, there is spacing. I try to constantly change that, and it almost never works. Using <code>android:stretchMode</code> does change it, but it messes up the spacing I have between the cells, so thats not working. Using Gravity also fails as you can see. I've tried all the other values for it and it still changes nothing. It's stuck to the left. I also find it weird that trying to change the size of <code>android:columnWidth</code> from anything under 40 it does nothing either. And when I increase 40 to 45, it also changes nothing. But changing it to 50 makes the space on the right go away. But when putting it on my phone, the spacing is there! I skipped this like 2 weeks ago to continue working on other stuff but it looks like I have yet to solve this issue or even understand why nothing I try works.</p>
  
  <p>If it helps anyone help me out here I can also provide the xml for what makes the cells. But I am not sure if it matters. But here it is:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical" &gt;
      &lt;TextView 
          android:id="@+id/day_num"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:textSize="10dp"
          android:background="#000000"
          android:height="35dp"
          android:gravity="center_vertical|center_horizontal" /&gt;
  
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>If it helps, the <code>GridView</code>'s parent is a <code>LinearLayout</code> with this:</p>
  
  <pre><code>&lt;LinearLayout
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:orientation="vertical"
      android:layout_weight="0"
      android:gravity="center" &gt;
  </code></pre>
  
  <p>There is also a sibling with a weight of 1, but I don't think that should be effecting is as the weight of 0 makes that part set its space first.</p>
  
  <p><strong>EDIT</strong>:</p>
  
  <p>So I have kept playing with it, very annoyed, especially since not that many people seem to have this issue, but it looks like no matter how small I make the <code>columnWidth</code>, the GridView barely gets any smaller. In fact, that same gap you see is what it stays at until I go to 50dp. But when I go in portrait mode the gap reappears, so I raise it up to 90dp (I tried under that, didn't change anything), and it goes away. Weird thing is the <code>GridView</code> doesn't change besides the filling of the gap. So I could make it 200dp, and it would look perfect on my screen dimen, and any other smaller screen. Once I go to a tablet, I suspect I would need to increase that more, but the point is, this is weird behavior. Has anyone encountered this?</p>