user3600338
user3600338

Reputation: 119

GridView items containing a single image does not match the height of the image even though it's set to wrap_content

I have the following GridView:

<GridView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/gridView"
    android:layout_alignParentTop="true"
    android:layout_alignParentStart="true"
    android:numColumns="3" />

Which I populate with this type of items:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageView"/>
</LinearLayout>

I set the image in the adapter by setting a bitmap. The images get the appropriate size for a GridView with 3 columns, but the items are way too high. This means that there is a lot of empty space above and below every image. How can I remove that space so the items have the same height as the images?

Here's an illustration of how it is right now: enter image description here

Here's how it should be: enter image description here

Upvotes: 0

Views: 86

Answers (1)

santosh kumar
santosh kumar

Reputation: 2962

Add this in xml,

<ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:adjustViewBounds="true"
        android:id="@+id/imageView"/>

Upvotes: 1

Related Questions