Nehara Ranathunga
Nehara Ranathunga

Reputation: 89

Android: Table Row Image is fattened and does not maintain aspect ratio

I have an ImageView inside a TableRow which needs to basically display the image by maintaining its aspect ratio. However this is what I end up with:

enter image description here

Here's my XML for the TableLayout and that specific row only:

<TableLayout
     android:id="@+id/tableLayout1"
     android:layout_width="match_parent"
     android:layout_height="match_parent" >

     <TableRow
          android:id="@+id/tableRow2"
          android:layout_width="match_parent"
          android:layout_height="fill_parent"
          android:padding="5dip" >

                 <ImageView
                    android:id="@+id/producImagScroller"
                    android:layout_width="match_parent"
                    android:layout_height="fill_parent"
                    android:background="@drawable/girl2" >
                 </ImageView>
      </TableRow>

What do you think is wrong?

EDIT: After trying Greg Ennis's answer:

enter image description here

Upvotes: 0

Views: 188

Answers (1)

Greg Ennis
Greg Ennis

Reputation: 15379

Instead of this

android:background="@drawable/girl2" 

You should set

android:src="@drawable/girl2" 

After doing this, try adjusting the image scaleType attribute. (Works only if you change background to src).

Upvotes: 1

Related Questions