Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perfectly linear spacing between gridview items

I am using following code to show the GirdView items.

<GridView
            android:id="@+id/gridView"
            android:gravity="center_horizontal"
            android:layout_below="@+id/searchLayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:horizontalSpacing="10dp"
            android:numColumns="3"
            android:stretchMode="columnWidth"
            android:verticalSpacing="10dp" />

Each GridItem (ImageView) is of size 92dp

What i want is to show only 3 Columns or 3 images each Row and each Top, bottom ,left right all needs to be perfectly aligned and equal.

Below is the result of above code.

enter image description here

It can be seen that spaces on left and right of the grid are very less as compared with the ones in between images and also between rows are very small.

Secondly, I am using 92dp. above is the result of S3, but when i use small screen the 3rd image doesn't get fit like in 320 dp screen.

Shouldn't using "dp" automatically adjust according to screen size?

like image 308
Muhammad Umar Avatar asked Feb 13 '26 21:02

Muhammad Umar


1 Answers

I think this code will help you try it :-

GridView
android:id="@+id/grid_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:numColumns="3"
android:gravity="center"
android:stretchMode="columnWidth"
android:background="#000000"/>
like image 176
Mitul Gedeeya Avatar answered Feb 16 '26 09:02

Mitul Gedeeya