itsDiogo
itsDiogo

Reputation: 63

wrap_content larger than actual imageview

I have a simple question, I have a simple RelativeLayout with a single ImageView (soon to add more). However, the width and height of the ImageView are set to wrap_content but when checked, the width is aligned properly (probably because its the max width of the screen) but the height seems to wrap further than the actual image. The images were made via Adobe Illustrator and then exported out as a .png with a DPI of 480.

Example:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    tools:context=".MainActivity"
    android:background="#d1070707">


 <ImageView
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:id="@+id/outer_shell"
     android:layout_centerVertical="true"
     android:layout_centerHorizontal="true"
     android:src="@drawable/out_shell" />

</RelativeLayout>

[Couldn't post direct images due to rep < 10 but I wanted to show my issue for a better understanding, links direct to the images]

The issue: http://postimg.org/image/75ijbo1zv/

Show that my image has no larger border: http://postimg.org/image/mog8ijghb/

However, If I were to move the image further down where the wrapped content area would theoretically get cut off, it resizes itself (height) smaller and smaller depending on the margin value I set. So, if anyone has any idea why it acts like this and can explain, that would be great!

Upvotes: 6

Views: 1685

Answers (1)

sindyoke
sindyoke

Reputation: 494

It's an old question but someone may stumble upon it, so I'll leave an answer.

I had the same problem, and setting android:adjustViewBounds="true" helped me. It makes the ImageView resize itself to fit the image.

Upvotes: 19

Related Questions