See attached screenshot where I am attempting to reduce the space between the columns in my GridView.
My main.xml is as follows:
Hi i had the same problem i solved by mygridView.setStretchMode(GridView.NO_STRETCH);
I had the same problem. I minimized column space by doing this
for gridView
android:numColumns="2"
android:columnWidth="90dp"
android:verticalSpacing="0dp"
android:horizontalSpacing="-30dp"
android:stretchMode="columnWidth"
for imageView
android:layout_width="115dp"
android:layout_height="150dp"
android:padding="1dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="-15dp"
Remove Gravity attribute and use the following mode
android:stretchMode="NONE"
I was having similar issue of having slight horizontal spacing between the columns in few devices. ( I did not required any space. ) I was properly calculating the grid item width by dividing it with total width. I was getting this issue only on Lenovo devices.
following code was in activity related to grid.
int myRequestedColumnWidth = myGridViewContentMain.getRequestedColumnWidth();
Point size = new Point();
getWindowManager().getDefaultDisplay().getSize( size );
int width = size.x;
int height = size.y;
int myGridColumns = width / myRequestedColumnWidth;
if ( myGridColumns == 0 || myGridColumns == 1 )
myGridColumns = 2;
myColumnWidth = ( width / myGridColumns );
myGridViewContentMain.setNumColumns(myGridColumns);
following code was in layout xml for grid
<GridView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/gridViewContentMain"
android:layout_centerHorizontal="true"
android:numColumns="2"
android:columnWidth="200dp"
android:verticalSpacing="0dp"
android:layout_below="@+id/relativeLayoutMainHeader"
android:layout_above="@+id/relativeLayoutProgressBar"
/>
I was unable to solve issue after changing stretch mode values.
But following value in layout xml for GridView did the trick.
android:horizontalSpacing="0dp"
I hope, someone like me may find this helpful.
Regards.
You can reduce the space b/w column by setting the android:horizontalSpacing="-10dp" ( some negative number )
try to fix the number of columns needed in xml file for grid and set stretchMode as columnwidth
android:numColumns="3"
android:columnWidth="60dp"
android:stretchMode="columnWidth"
or set the horizontal and vertical spacing in xml for grid
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"