Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove the space between rows of grid view in android

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.

Image for reference. this is what happening right now.

like image 267
Dipali Avatar asked Feb 03 '12 07:02

Dipali


1 Answers

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

like image 154
Dipali Avatar answered Oct 14 '22 09:10

Dipali