Android gridview imperfection, how to remove excess space on the right

I have a GridView based calendar. I have the following XML format with a selector set to zero, thus android:listSelector="@null"in accordance with the recommendations I received from this site. Now I get a strip a few pixels wide to the right of the GridView. What for? I tried everything I could, but use it. 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 a picture:

enter image description here

+5
source share
5 answers

. , 320 , 7 , , 320 px. 45,71428571428571 px, .

Android: = ""   ,

+6

1dp

android:horizontalSpacing="1dp"

, , -1dp

android:paddingRight="-1dp"

- ,

+3

android:layout_margin="0dp"
android:padding="0dp"

.
?

0

, GridView, . .
, onMeasure .
- :

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    final int RIGHT_MARGIN_OVERSIZE_DIP = 6;
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    int width = this.getMeasuredWidth()
    int overSize = (int)((getResources().getDisplayMetrics().density*RIGHT_MARGIN_OVERSIZE_DIP) + 0.5f);
    widthMeasureSpec = MeasureSpec.makeMeasureSpec(width + overSize, MeasureSpec.getMode(widthMeasureSpec));        
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
0
grid.setColumnWidth(grid.getColumnWidth()+1);

ColumnWidth 1 . onCreateView, .

, match_parent ( ). / match_parent.

0

All Articles