title: Android: center gridview horizontally
body: <p>I need to center grid view horizontally in my android layout.xml. I have searched google for quite a while but didnt succeed in finding an answer. </p>
  
  <p>I can only change gridview horizontal position by changing strechMode, but then my items are not near one another.
  that i need is items  be one near another (without spaces) and centered horizontally. I choose strechmode = none, so now my items are near one another, but they are on the left of the screen, i just want them to be centered horizontally.</p>
  
  <p>Here is my layout xml:</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent" 
            android:layout_height="fill_parent"
            android:background="@drawable/background" 
            android:gravity="center"&gt;
  
  &lt;GridView android:id="@+id/lw_gridview" 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:numColumns="3" 
            android:columnWidth="48dp"
            android:horizontalSpacing="0dp"
            android:verticalSpacing="0dp"
            android:stretchMode="none"
            /&gt;
  
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>Here is fragment of an image which is set on gridview by image adapter:</p>
  
  <pre><code>imageView = new ImageView(context);
  imageView.setLayoutParams(new GridView.LayoutParams(48,48)); //on medium density
  imageView.setScaleType(ImageView.ScaleType.CENTER);
  imageView.setPadding(0, 0, 0, 0);
  </code></pre>
  
  <p>How can i succeed? </p>