Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android GridView imperfection, how to remove extra white space to the right

I have a GridView based calendar. I have the following XML layout with the selector set to null thus android:listSelector="@null" in accordance with advise I have got from this site. Now I am getting a few pixels wide strip to the right of the GridView. Why? I have tried everything I can but to avail. Here is my XML layout:

        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent"
            android:layout_height="match_parent"
            android:orientation="vertical" >

            <GridView
                android:id="@+id/calendar"
                android:layout_width="fill_parent"
                android:layout_height="match_parent"
                android:horizontalSpacing="-1px"
                android:numColumns="7"
                android:stretchMode="columnWidth" 
                android:gravity="center"
                android:verticalSpacing="-1px"
                android:listSelector="@null" >

            </GridView>

        </LinearLayout>

What I get is this picture:

enter image description here

like image 648
Lukuluba Avatar asked May 23 '12 13:05

Lukuluba


2 Answers

This space is due to imperfect calculation for each row of your grid. For example your device width is 320 px and you have 7 rows, try any calculation that meets 320 px. If the width of each cell is 45.71428571428571 px, only then it can be reduced.

Other option

apply android:gravity="center" property in you grid so that spaces will equally divided from left to right

like image 181
dinesh sharma Avatar answered Nov 11 '22 12:11

dinesh sharma


in my case I had horizontal spacing as 1dp

android:horizontalSpacing="1dp"

so to solve this I just put the right padding as -1dp

android:paddingRight="-1dp"

even though I expected to get a space on the left side due to this , but it worked properly

like image 25
Jimmar Avatar answered Nov 11 '22 11:11

Jimmar