Which stretchMode to use in GridView on android
android, gridview, layout
Solution
A combination of `android:numColumns="auto_fit"` `android:stretchMode="columnWidth"` and `android:columnWidth="60dp"` will give you a layout that adjusts for different screen sizes. Much better than fixing the number of columns. See example below...
<GridView
android:id="@+id/tablegrid"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffff7965"
android:horizontalSpacing="5dp"
android:verticalSpacing="5dp"
android:layout_marginStart="5dp"
android:layout_marginLeft="5dp"
android:numColumns="auto_fit"
android:stretchMode="columnWidth"
android:gravity="center"
android:columnWidth="60dp"
/>
Problem
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?