user5045814
user5045814

Reputation:

ImageView leaves a lot of free space

I need to make a table with pictures. So I decided to do it with TableLayout (instead of TableRow i used LinearLayout cause of weightSum). There is a code:

<TableLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

        <LinearLayout
            android:orientation="horizontal"
            android:weightSum="3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">

            <ImageView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:src="@drawable/card_shirt"
                android:id="@+id/imageView"
                />

            <ImageView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:src="@drawable/card_shirt"
                android:id="@+id/imageView2"/>

            <ImageView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:src="@drawable/card_shirt"
                android:id="@+id/imageView3"/>
        </LinearLayout>

        <LinearLayout
            android:orientation="horizontal"
            android:weightSum="3"
            android:layout_width="wrap_content"
            android:layout_height="match_parent">

            <ImageView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:src="@drawable/card_shirt"
                android:id="@+id/imageView4"/>

            <ImageView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:src="@drawable/card_shirt"
                android:id="@+id/imageView5"/>

            <ImageView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:src="@drawable/card_shirt"
                android:id="@+id/imageView6"/>
        </LinearLayout>
</TableLayout>

It's not a whole code, in my app i do it dynamically, but it doesn't change the essense.

So the issue is on a picture below:

enter image description here

What is the free space above and below each picture? How can i get rid of it?

Upvotes: 1

Views: 76

Answers (2)

Sakthivel Appavu
Sakthivel Appavu

Reputation: 575

You can also to set

android:scaleType="centerCrop"

Upvotes: 0

Sruit A.Suk
Sruit A.Suk

Reputation: 7273

It's happen because of ImageView auto detect the width and height of real image

However , the width is not enough, so the ImageView auto resize the image to fit for it's width

and that's why their height is still there, and display as free space as you mention

How to solve

make sure you add

android:adjustViewBounds="true"

in ImageView

or just clicked at this checkbox

enter image description here

Upvotes: 1

Related Questions