user3607798
user3607798

Reputation: 769

Showing the images in the Gridview

i'm using the gridview to display the images.

<GridView
    android:id="@+id/gridView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:columnWidth="96dp"
    android:numColumns="auto_fit"
    android:stretchMode="columnWidth" >
</GridView>

and the imageview is

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="96dp"
    android:layout_height="96dp"
    android:background="@drawable/image_bg"
    android:scaleType="fitXY"
    android:src="@drawable/ic_launcher" />

Note : I dont want to hardcode the numbers of images to display in single row of gridview because if the screen orientation changed the number changes

When i'm loading m getting the space bewteen the images in the gridview as the below pictureenter image description here

But i dont need the space i want the gridview to appear like the native gallery

Upvotes: 0

Views: 65

Answers (3)

Palak
Palak

Reputation: 2215

Change layout_width android:layout_width="match-parent" instead of "96dp"

Upvotes: 1

Sagar Pilkhwal
Sagar Pilkhwal

Reputation: 3993

add this to your gridview xml :

android:listSelector="@android:color/transparent"

and also try myGridView.setStretchMode(GridView.STRETCH_COLUMN_WIDTH);

Upvotes: 0

Amit Gupta
Amit Gupta

Reputation: 8939

Try using below tag in GridView

android:verticalSpacing="10dp" // changed this value
android:horizontalSpacing="10dp"

For reference HorizontalSpacing and VerticalSpacing

Upvotes: 0

Related Questions