Search code examples
androidandroid-drawablescreen-orientationandroid-image

Android won't use my long (wide aspect ratio) drawable images on long devices


I have a multi-page app that is working great except for image loading. Each page has a fullscreen image. I have 5 drawable folders -- the default one without any page images in it and then these four:

  • drawable-long
  • drawable-notlong
  • drawable-long-xhdpi
  • drawable-notlong-xhdpi

My app is set to only landscape. The image files in notlong are 4x3 aspect ratio. In long they are 16x9 aspect ratio.

On the Nexus 7 and 5, both devices report a screen type of long yet use the 4x3 images from drawnble-notlong-xhdpi. How can I get them to use the long images?

If I remove the two notlong folders, on app startup I get a NotFoundException on the image resource (which crashes the app).

I did add the equivalent layout views but still the 4x3 image is being displayed.


Solution

  • This is a duplicate of Android resource notlong / long identifiers not working as it turns out there was a bug -- my code telling me if the screen was long or not was wrong. For a Nexus 7, 1920/1200 = 1.6 which is less than the 1.667 ratio that triggers the long view as mentioned in the linked to Q&A. So Android is working correctly however the normal aspect ratio can be quite a ways from 4x3 so one has to take that into account.