Following is my xml code:
<?xml version="1.0" encoding="utf-8"?>
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gridviewgallery"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnWidth="@dimen/gridview_column_width"
android:numColumns="auto_fit"
android:verticalSpacing="0dp"
android:horizontalSpacing="0dp"
android:stretchMode="columnWidth"
android:gravity="center"
android:background="#444444"
/>
When I use android:stretchMode="columnWidth" , it creates a gap between the columns(though it fills the screen width) And if I use android:stretchMode="none" , it gets left aligned and there is a gap left on right side of screen(though now there is no gap between columns) Problem is I want both : To fill the screen width as well no gap between columns. How to achieve it?
I know this question is a little old but here is an answer I found hoping this helps someone else, just for
android:stretchMode
usespacingWidthUniform
as it says in documentation here it will stretch the spacing between columns equally.please refer to above link for more information.
A combination of
android:numColumns="auto_fit"
android:stretchMode="columnWidth"
andandroid:columnWidth="60dp"
will give you a layout that adjusts for different screen sizes. Much better than fixing the number of columns. See example below...It's very simple dude, just remove the line
you can specify any number of columns, i am given number of column = 4
This is working fine for me