0

I am new to making android apps and I'm currently making one that requires a large image (3000x2500 px and it's a jpeg) to be able to scroll around the screen with multiple device resolutions. I'm trying to figure out what layout directories I should have for the popular android phones.

So far I have:

  • sw360dp
  • sw384dp
  • sw480dp

From my understanding of my google searches for help and from what I've seen in my app, the formula to check which directory a phone should use is

DPI = ((sqrt)(resolution_width^2 + resolution_height^2)) / diagonal screen length

then,

scalingDensity = DPI / 160

and finally,

layout directory = resolution_width / scalingDensity and you round the answer to the nearest .5

So for example, the Samsung Galaxy S3 has a resolution of 720x1280 with a diagonal length of 4.8" then the

DPI = 305.96, scalingDensity = 1.91 (Round up to 2), and the layout directory is sw360dp (720 / 2).

In my app, testing on a Samsung Galaxy S3 will use the sw360dp layout like I expected (I put a tag in each xml and just print out the tag to see which layout my app is using)

But there are some devices that don't use what I expect? For example, the Nexus 6 (1440x2560 with a diagonal distance of 6") which should use the sw480dp but it uses sw384dp (which I made for the Nexus 4)

If anyone can help me with this or clarify if I'm even calculating these right, please let me know. It is greatly appreciated.

  • you should probably be putting that image in the nodpi folder, also an image that size is going to cause you problems, you will need to resize it when you load it or you will get OOM errors. Also you should not be targeting specific devices – tyczj Jul 20 '16 at 19:11
  • I actually am having problems with the image and OOM errors but since I am new, I wanted to tackle one thing at a time. What would you suggest to do about the resizing? And what's the difference between putting the image in a nodpi or specific sizes? – Str8UpEliTe Jul 20 '16 at 19:13
  • http://stackoverflow.com/questions/34156957/what-is-the-difference-between-anydpi-and-nodpi – tyczj Jul 20 '16 at 19:17
  • 1
    I think http://stackoverflow.com/a/30041754/436938 answers your question about Nexus 6 – Sergey Glotov Jul 20 '16 at 19:18
  • Oh okay, so I'll move it to the nodpi folder, what do you suggest to do about the large image size? My app needs a large image because there are buttons on top of certain areas of the image and I don't want to make the image too small that the user won't be able to press the buttons – Str8UpEliTe Jul 20 '16 at 19:23
  • you have to scale your image to the size of the imageview that you are putting it in. http://stackoverflow.com/questions/477572/strange-out-of-memory-issue-while-loading-an-image-to-a-bitmap-object – tyczj Jul 20 '16 at 19:37
  • Do I keep the sw...dp directories I have? What's better to use, sw...dp or layout-large, layout-xlarge, etc? – Str8UpEliTe Jul 20 '16 at 20:56

0 Answers0