Image resize when running the app on my device (Android Studio)

380 views Asked by At

I'm just starting with Android Studio and I have an old device running Android Froyo (API 8) with 240x320px display resolution.

  • I have an image with 240px width and when I use an ImageView with wrap_content to display that image on my device, it doesn't use the whole width of my device screen.

  • When I set the ImageView width to 240px, It occupies the whole width of my device (so I know my device has actually 240px width), but I can see it's blurred out.

Apparently the image is being resized to a lower resolution before being compiled and loaded to run on my device.

If anyone can help me explaining why this happens, I would really appreciate, because I couldn't find out, searching here and on Google.

.

Thanks!

1

There are 1 answers

0
Fabiano On

As I didn't get an answer to my question, thinking overnight, I believe I figured it out.

  • My display has 2.8", so I thought it's density would be around 143dpi ( SQRT(240^2+320^2)/2.8 ).
  • With that density, objects declared in 'dp' would take too much space on the screen.
  • So, after comparing the 'dp' value with the actual number of pixels on my screen, I found out its density is actually 120dpi (LDPI), so a 160dp object actually doesn't have one inch on my screen, but 3/4 of an inch.

Maybe this is done by the device, not the compiler (I don't know), but everything I declare in 'px', is multiplied by 3/4 before loading due to its density.

I hope I'm right and that I have helped anyone with the same doubt.