问题
In android grid view there is extra space between the rows of grid view. I am not adding any space to the gridview.
here is my xml files
<GridView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/grid"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:horizontalSpacing="5px"
android:numColumns="3"
android:columnWidth="50dip"
android:verticalSpacing="0dip"
android:gravity="center"
/>
and the other xml for the imageview which is adding view to the gridview is
<ImageView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/singlePhoto"
android:layout_gravity="top"
android:layout_width="145dip"
android:layout_height="145dip"
android:layout_marginTop="0dip"
android:layout_marginBottom="0dip"
>
</ImageView>
In Adapter class the code is
if(mView == null){
mView = mLayoutInflater.inflate(R.layout.newsgridthumbpic, null);
}
ImageView mImage = (ImageView)mView.findViewById(R.id.singlePhoto);
PhotoGridInfoSet mInfo = (PhotoGridInfoSet)details.get(position);
if(mImage != null){
mImage.setTag(mInfo.getPhotoThumbNailString());
mImage.setVerticalScrollBarEnabled(true);
mImage.setVerticalFadingEdgeEnabled(true);
}
}!
The space is between the rows of gridview. I have not added any space anywhere in the code Still the there is vertical spacing.I am not able understand why there is space in between gridview rows. This space is not appearing in the hdpi device/emulator. This problem is in the mdpi and ldpi devices/emulator.

回答1:
I got the solution for this problem.
To solve this i need to add 1 line in my xml file
android:adjustViewBounds="true"
and after adding this. the space is not appearing now
回答2:
Just put last 2 lines in gridView
<GridView
android:numColumns="2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/gridView"
android:horizontalSpacing="0dip"
android:verticalSpacing="0dip"/>
回答3:
Put the following line in ur getView() method...
mImage.setPadding(0, 0, 0, 0);
I hope this will help you.
回答4:
It looks like your picture is being scaled to fit the column width of 50dp while maintaining the aspect ratio. This is introducing a bunch of unfilled space in the vertical layout. If you want your column to be 50dp wide, the easiest way to work out these spacing issues will be to adjust your imageview to have a width of 50dp and adjust the imageviews height proportional to that.
回答5:
just check that your "newsgridthumbpic" layout does not contain the extra padding or any background image having a large height that your grid view element.
Also double check that you are supplying column_width as 50dip but your "imageview's" width is 145 dip.
回答6:
<GridView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/grid"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:horizontalSpacing="5px"
android:numColumns="3"
android:columnWidth="50dip"
android:verticalSpacing="0dip"
android:gravity="center"/>
<ImageView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/singlePhoto"
android:layout_width="145dip"
android:layout_height="145dip"
android:scaleType="fitXY">
</ImageView>
回答7:
Setting android:verticalSpacing in the gridview to negative values. will remove the vertical space.
(Eg: android:verticalSpacing="-10dp")
test with some number to get the right value
来源:https://stackoverflow.com/questions/9125014/how-to-remove-the-space-between-rows-of-grid-view-in-android