Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GridView auto fit images

im trying to get images displayed in a GridView and get the columns automatically set, so far I've had to manually set the number of columns which is not what i want to do as this will affect how big the images are on different sized screens. I ahve tried setting it to auto_fit but it only displays 2 columns in the middle of the screen. This is what im trying to achieve: (Each red square represents an image)

enter image description here

then when turned to landscape mode i want the columns to auto fit so that its all even. Any help would be much appreciated, thank you :)

like image 205
Tom O Avatar asked May 03 '11 16:05

Tom O


1 Answers

Experiment with the GridView attributes, specifically android:numColumns="auto_fit" and android:stretchMode. The following works for me:

<GridView      android:id="@+id/myGrid"     android:layout_width="fill_parent"      android:layout_height="fill_parent"     android:padding="10dp"     android:verticalSpacing="10dp"     android:horizontalSpacing="10dp"     android:numColumns="auto_fit"     android:columnWidth="60dp"     android:stretchMode="columnWidth"         android:gravity="center" /> 
like image 122
Jeff Gilfelt Avatar answered Sep 26 '22 15:09

Jeff Gilfelt