0

I'm displaying some images from the RESTFul web service via GridView. Maximum rows number is 4. How to calculate optimal width of image depends on that that screen can be in portrait mode and in landscape mode? Or I should use some constants for that, depends on screen density?

Near1999
  • 1,547
  • 2
  • 18
  • 37
  • Get the device screen width on pixels, then just make any calc you need to find the needed width, did you have any problems with this? – Nanoc Nov 05 '15 at 16:30

2 Answers2

0

PLay with the GridView attributes, specifically android:numColumns="auto_fit" and android:stretchMode. For example:

<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"
/>
PurpleSoft
  • 146
  • 11
0

I would create/update the grid params on runtime, just before downloading the image.

See this post for getting the view's width/height on run-time.

BTW - I strongly recommend ImageDownloader to download and display image - it can use cache and save memory while loading scaled images.

Community
  • 1
  • 1
Asaf Pinhassi
  • 15,177
  • 12
  • 106
  • 130