0

I have a GridView which displays the user's photos. What I want to find is the exact columnWidth I have to specify so that the number of columns will vary from device to device, but always take up the entire screen (like QuickPic does). Right now my code is as follows:

//GridView inside Fragment layout file
<GridView
    android:id="@+id/gridview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:columnWidth="90dp"
    android:horizontalSpacing="2.75dp"
    android:verticalSpacing="2.75dp"
    android:numColumns="auto_fit"
    android:stretchMode="columnWidth" />

 //GridView row

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content">

     <ImageView android:id="@+id/ivPhoto"
         android:layout_width="90dp"
         android:layout_height="90dp"
         android:scaleType="fitCenter" />
</RelativeLayout>

With my code, I get a lot of whitespace I don't want. I want it to have whitespace, but very little. I want the Grid to fill the entire screen with columns (photos), but leaving some little whitespace between them.

What would the perfect columnWidth be?

Thank you.

fergaral
  • 2,077
  • 6
  • 17
  • 34

1 Answers1

0

Making the Gridview adapt to different screen sizes is a little tricky using xml. A good solution is to adjust the size of the gridviews in your adapter's getView() method.

check out this example. Adjust GridView to all Screen Sizes

Community
  • 1
  • 1
Ronny K
  • 3,641
  • 4
  • 33
  • 43