Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImageView within RelativeLayout has top and bottom padding

I have a 640px wide, 208px tall PNG that I've placed in my /drawable folder and I'm having a very hard time properly placing it in an ImageView. I want to scale the image so that it maxes out the horizontal resolution, and I want it to scale vertically only as much as it takes to stay in proportion.

The problem I am having is that my ImageView ends up taller than it needs to be to fit the image. The image itself looks perfect; as wide as the screen and in proportion. But the ImageView appears to have padding on the top and bottom. From what I can tell it's the drawable that the ImageView contains that's actually too tall.

I can't post an image because I'm new to SO, but if I did it would be of the Graphical Layout view. When I click on the ImageView the regular blue box shows up around it, but with padding on the top and bottom, the same padding I'm seeing on the device. Even if I drag the blue box to attempt to resize the ImageView, I am not allowed to make it any smaller than it already is (perhaps because the ImageView thinks the drawable is that tall, or something). From what I can tell, this may have something to do with the density of the image...the ImageView ends up being 312 pixels tall (208*1.5) on an hdpi device.

Here is my XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    <ImageView android:id="@+id/back" android:src="@drawable/categoryheader2"
        android:layout_width="wrap_content" android:layout_height="wrap_content">
    </ImageView>
</RelativeLayout>

Thanks in advance for any help!

like image 694
Sam Dozor Avatar asked Sep 29 '11 18:09

Sam Dozor


2 Answers

I guess android:adjustViewBounds="true" on the ImageView should do the trick. I recently had a similar problem, when I was trying to scale an image to fit the whole width of the view without loosing its proportions.

like image 193
jhunovis Avatar answered Sep 21 '22 06:09

jhunovis


did you tried the tag : android:scaleType="fitXY" or android:scaleType="centerCrop" on your ImageView ?

like image 1
Houcine Avatar answered Sep 20 '22 06:09

Houcine