views:

739

answers:

1

I can't seem to get my ImageView to display its source image in its original size. The ImageView looks like this:

   <ImageView 
 android:id="@+id/Logo" 
 android:src="@drawable/logo"
 android:layout_width="wrap_content" 
 android:layout_height="wrap_content"
 >
</ImageView>

The source image is 140 pixels wide, yet on the Nexus One's screen, which is 480 pixels wide it uses up half of the width. Using absolute values in px or dp for the width and height changes nothing. The image also looks very antialiased from the upscaling. Why is this happening and how can I prevent it?

+2  A: 

Most likely, Android is scaling up the image, because you did not tell it you were supporting large screens. Add a suitable <supports-screens> element to your manifest and see if that helps.

CommonsWare
I just tried your suggestion and it definitely has something to do with that. Thank you very much! The image has the "correct" size now if I use the dimensions of the image as absolute pixel values for layout_width and layout_height. If I use wrap_content the image is still as large as before, which, as It seems, is also the same size as when I use the dimensions of the image with "dp" as dimension. I guess this is just how wrap_content works. In that case it would make sense that the image gets displayed too large on a device with a high density screen like the Nexus.
legr3c
What's still strange is that if I use wrap_content for layout_width and layout_height but use the absolute pixel values for maxWidth and maxHeight that has no effect. Since the usage of pixel dimensions is discouraged anyways I wonder whether there are any other ways to prevent the image from being upcaled?
legr3c
You probably want two versions of your image anyway, one for medium density screens and one for high density screens. Try putting your image in `res/drawable-hdpi/` and see if that helps.
CommonsWare
Could you please check out this question. It's related.http://stackoverflow.com/questions/3296227/android-resizing-and-scaling-a-part-of-the-image
Namratha