Question: See attached screenshot where I am attempting to reduce the space between the columns in my GridView.

My main.xml is as follows:

```
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<GridView 
android:id="@+id/gridview"
android:layout_width="wrap_content" 
android:layout_height="wrap_content"
android:stretchMode="columnWidth"
android:gravity="center"
/>
<LinearLayout 
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
    <ImageView 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/logo"/>
    <TextView
    android:text="@string/game_score"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:layout_gravity="center"/>
</LinearLayout>
</LinearLayout>

```

I am creating the ImageViews in my code from a Bitmap. However, I am not specifying any padding or spacing or otherwise.

How can I reduce this space between columns? I've tried a variety of settings on both GridViews and ImageViews but with no luck

Image is ![here](https://i.stack.imgur.com/LxYvC.jpg): 

Thanks

Answer: 
Remove Gravity attribute and use the following mode

```
android:stretchMode="NONE"

```
Space between columns is because your gridview element is not completely occupying the column space provided by grid view.

The solution to remove space between columns is to measure the device's screen width and height and divide it by the number of columns and rows. This will give the width and height for each grid view element.

you have to assign this height and width to imageview and also scale your bitmap to match the imageview.

Code: 

```
  DisplayMetrics displayMetrics=getResources().getDisplayMetrics();
  screen_width=displayMetrics.widthPixels;    //width of the device screen
  screen_height=displayMetrics.heightPixels;   //height of device screen

     int view_width=screen_width/number of columns;   //width for imageview
     int view_height=screen_height/number of rows;   //height for imageview

   Imageview myImageView=(ImageView)findViewById(R.id.my_id);
   myImageView.getLayoutParams().width=view_width;
   myImageView.getLayoutParams().height=view_height;

   Bitmap myImage=Bitmap.createScaledBitmap(src, view_width, view_height, true);//scaling the image to match the size of image view

```