Android resourse folders swXXXdp for 5 inch phones - android

I want to distinguish phones with ~5 inch and higher displays from 4 inch 480x800 in my res/values folder
How can I differentiate ~5 inch displays?
I should probably use this trick, but what should got instead of XXX?
values-swXXXdp?
Especially I am trying to differentiate Galaxy S 3 and Galaxy S 4 from others. What should I consider?

S3:
DPI: 306
RES: 1280x720
Screen: 4.8"
720 / (306/160) = 720 / 1.9125 = 376.47 dp
S4:
DPI: 441
RES: 1920x1080
Screen: 5.0"
1080 / (441/160) = 1080 / 2.75625 = 391.8367 dp
So basically there is a very small difference between S3 and S4. But if you want to distinguish layouts for these devices, use sw376dp for S3 and sw390dp for S4. But make a note that other 5" phones could be different.

Related

Cannot address 10 inch tablet (Galaxy Tab A7) with layout file using Android?

I would like to address the Galaxy Tab A7 with a layout file. Unfortunately the layout file of smaller tablets (7 inch tablets) is used. I debugged the app on the 10 inch Galaxy Tab A7 and get the following values:
dpi: 280
Screen dimensions: 1200x1916px
density: 1.75
aspect ratio: 3:5 (0.6)
From my opinion, this implies that it has xhdpi resolution. Is this right? And the problem is that it does not belong to sw720dp (as this would require a larger width). How might it be possible to use a layout file for 10 inch tablets for this tablet? Is it possible?

Galaxy tab 2 7" does not fit sw600dp?

Everywhere in Android documentation I can ready that I have to use sw600dp for 7 inch tablets, but this does not seem to be true, because Galaxy Tab 2 7" has 546dp for its smallest width.
http://www.gsmarena.com/samsung_galaxy_tab_2_7_0_p3100-4543.php
dp = 600 / (170 / 160) = 546
Should I use sw500dp in my layouts instead?
Android device pixel densities are classified in buckets:
While the Galaxy Tab 2 screen may actually be 170 dpi, that falls within the range of mdpi which translates to 160 dpi being used in practice for dp calculations. The device should still have a 600dp width.

How to create different layout for Galaxy S4 and Nexus 4

I am using "layout-sw360dp" for both Galaxy S4 and Nexus 4 devices but in my screen displaying some space on Galaxy S4. so can i make different layout for both Galaxy S4 and Nexus 4. if it is possible then please give me the solution.
For Galaxy s4 use layout-xxhdpi
For Nexus 4 use layout-xhdpi
Galaxy S4 -- 1080 x 1920 pixels -- 5.0" -- 441 ppi -- xxhdpi
Nexus 4 -- 1280 x 768 pixels -- 4.7" -- 320 ppi -- xhdpi
You have to make different images to fit to the resolution of these devices
As per other answers one device is 640 x 360 dp and the other 640 x 384 dp.
You don't want to make a different layout for them, because you will sooner or later see a device 640 x 372 dp or 640 x 388 dp.
Instead make your layout elastic and don't hardcode pixels (density independent pixels can also be badly hardcoded).
ok here goes...
for reference
this is older layout folder naming conventions but you get the point.
You must convert everything to mdpi to go into the following buckets.
buckets for layouts are :
xlarge 960 x720 min
large 640 x480 min
normal 470 x 320 min
small 426x 320 min
scaling ratio
3:4:6:8:12
this means that you must multiple ldpi * 3/4 to go from ldpi to mdpi
and you must multiple mdpi * 4/6 to go from mdpi to hdpi
and you must multiple hdpi * 6/8 to go from hdpi to xhdpi
and you must multiple xhdpi * 8/12 to go from xhdpi to xxhdpi
so to answer the question....
s4 is xxhdpi which means the scaling ratio is 4/12 or 1/3. This means that you have to convert from xxhdpi to mdpi to place in a layout folder properly.
so 1080 * 1/3 = 360
and 1920 * 1/3 = 640
so this would place it in a normal layout folder
nexus 4 is xhdpi which means the scaling ratio is 4/8 or 1/2. 4 This means that you have to convert from xhdpi to mdpi to place in a layout folder properly.
so 1280 * 1/2 = 640
and 768 * 1/2 = 384
so this would place it in a normal layout folder as well.
ok, so this doesn't quite cut it because they are different resolutions. we can make up folders with the new naming conventions. for example the smallest width for the s4 is 360 while the smallest width for the nexus 4 is 384. so folders could be sw360dp and sw384dp.
you could also name the folder layout-xxhdpi which would catch the s4 but not the nexus 4
be aware: Just to throw another one out there what if you had an s3 as well. that would go in the sw360dp folder as well. so I guess you would have to differ between them as well. if you used layout-xxhdpi above then you could use sw360dp here and sw384dp above as well. cover them all.
thanks
Both these phones have different screen size and resolution , that leads to different density as well .
As per my knowledge -
Galaxy s4 has 1080 x 1920 pixels, 5.0 inches (~441 ppi pixel density).
And
Nexus 4 has 1280 x 768 pixels, 4.7 inches (320 ppi ).
You will have to design the layouts (and images as well ) according to the phones specifications.
for nexus 4 use below layout.
layout-sw360dp
both galaxy s3 and nexus 4 have same layouts.

How to create different layout for Nexus 4 and similar devices? (Galaxy S4)

The question is how create a specific layout for Nexus 4 and similar devices?
4.7" diagonal
1280 x 768 pixel resolution (320 ppi)
WXGA IPS
For Nexus 4 should load the same layout that Galaxy S3
Galaxy S3
Screen Size: 4.8 inch
Screen Resolution: 1,280 x 720 pixels
And the configuration should be:
For same layout landscape and portrait layout-sw360dp
Only for landscape layout-sw360dp-land
Only for portrait layout-sw360dp-port
Other similar devices:
LG Optimus 4X HD
HTC One X+
For Galaxy S4 should also compatible and load this layout
The response was in this entry: Android S3 layout vs Galaxy Nexus layout
You can create layout directories for specific combinations. For 7" 1280 x 768 at 320 ppi it will look something like this:
layout-sw600p-xdpi-large
As #Tomer Mor mentioned, you can find a full list of available parameters here
Also, if you want to be even more specific about device parameters, take a look at this question - you can assign different layouts from code, depending on the environment.

Android resource size qualifier

I unable to get the values from "values-sw480dp" nor on my sony Xperia device which is 480 x 854 neither on Samsung galaxy tab which is 600 x 1024. But able to get on Motorola Xoom which is 1280 x 752.
e.g res/values-sw480dp/strings.xml/
<string name="hello_world">hello world</string>
The values on respective devices
Sony Xperia ----> #2131034113
Samsung ----> #2131034113
on xoom ---> hello world
Can any one explain me this behavior, why Sony Xperia and Samsung has "#2131034113" value.
Thank you in advance
According to http://developer.android.com/guide/topics/resources/providing-resources.html, sw480dp means «smallest side of screen must be at least 480 dp». Now dp is a «pixel on a 160 dpi screen», so actual size of e.g. Xperia in dp would be I guess 320 x 569 (provided it's a hdpi device).
To get device screen size in dp you need to know abstracted density class (ldpi=120, mdpi=160, hdpi=240, xhdpi=320). For the above Xperia screen the calculation is: (480*160/240) x (854*160/240), where 160 is the base density (it's where 1 dp actually equal to one pixel) and 240 is device abstracted density.

Categories

Resources