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.