Search code examples
androidandroid-layoutgridviewfill-parent

How to make the width of a grid view 100% across the screen


I have a grid view inside my layout and I am trying to make it stretch all the way across the screen. My XML for this gridview follows below.

 <GridView
    android:numColumns="auto_fit"
    android:gravity="center"
    android:stretchMode="columnWidth"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/gridView"
    android:layout_below="@+id/editText"
    android:columnWidth="400dp"
    android:clickable="true"
    android:background="#fffefff9"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true" />

The grid view does not completely fill the screens width. There are these small margins on the side. How do I get rid of these margins on the sides of the grid view completely? In other word, I want the width of the grid view to be full width. On the other hand, fill_parent does make the grid view's width cover 95% of the width of the screen, but there are small margins on the side of the screen. Unfortunately, I am not allowed to post an image since I don't have enough reputation.


Solution

  • Add this to your list view's parent it might be a linear layout or relative layout

    android:paddingBottom="0dp"
    android:paddingLeft="0dp"
    android:paddingRight="0dp"
    android:paddingTop="0dp"
    

    If there was already padding values change them to that.