2

I'm creating an app that downloads pictures from the web and shows them in a ImageView. I want to resize the image in the imageview proportionaly, so I used this code in 2.3.6 to accomplish this:

mImage.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
mImage.setAdjustViewBounds(true);
mImage.setScaleType(ScaleType.FIT_CENTER );

This worked pretty well, but on 4.1.2 (I don't have other versions of android 4.x) this seems to have no effect. The picture remains at top/left of the screen and without any resizing applied. Do anybody know what is happening? Did chang anything on 4.1.2 about this? Documentations doesn't state anything about it.

Thanks in advance.

Notbad
  • 5,936
  • 12
  • 54
  • 100
  • 1
    My assumption is that the density of the 2.3.6 device differs from your 4.1.2 device, which is most likely the problem here. Create a 4.1.2 emulator with the density and dimensions of your 2.3.6 device and see if your code works for that. If it does, you will know it isn't Android API specific. You may need to implement something similar to this (I did) - http://stackoverflow.com/questions/4677269/how-to-stretch-three-images-across-the-screen-preserving-aspect-ratio. – Steven Byle Feb 28 '13 at 17:46
  • I thought android were going to take of this by its own... Need to check this tonight. Thanks for the tip. Will come back with an answer soon. – Notbad Feb 28 '13 at 18:13
  • 1
    The issue I had was Android would only scale my images down, not up. So on a 480x800 device, a 500x500 image would get scaled down and fit just fine. But on a 720x1280, the same 500x500 image would max out at 500x500, and Android wouldn't scale it up beyond its real size. This is why I had to create a custom `AspectRatioImageView` (in the link) to force Android's hand, which works great BTW. – Steven Byle Feb 28 '13 at 18:44
  • Great I will test it right now. – Notbad Feb 28 '13 at 22:04
  • Yup, that was it. Thanks a lot. – Notbad Feb 28 '13 at 22:30

0 Answers0