Android layout-swXXdp for galaxy SII [duplicate] - android

I'm developing an Android Widget and need to differentiate between Galaxy S and Galaxy S2.
I almost read everything about Screen sizes and densities articles.
And I need, of course, to use the new qualifiers with the new qualifier Smallest Width.
My problem is, that the sw320dp qualifier match for Galaxy S and also for Galaxy S2.
But I need another layout for Galaxy S2, but cant find the right qualifier for it.
Definition of Galaxy S, Density 233
Screen Size in Pixels: 480 Pixel x 800 Pixel
Screen Size in dp: 329dp x 549dp (cause 1dp = 1pixel/(density/160)
-> so the qualifier sw320dp must match here. and yes it does
Definition of Galaxy S II, Density 218
Screen Size in Pixels: 480 Pixel x 800 Pixel
Screen Size in dp: 352dp x 587dp (cause 1dp = 1pixel/(density/160)
-> so the qualifier sw340dp must match here, but NO it doesnt
(Tested in emulator and on real device)
The drawables are not the problem, but my layout, especially the height and text sizes are different on these devices, so I really need a specific layout for them.
Anyone has an idea or more experience with it?

Screen density, as defined by the reference material is:
The quantity of pixels within a physical area of the screen; usually referred to as dpi (dots per inch). For example, a "low" density screen has fewer pixels within a given physical area, compared to a "normal" or "high" density screen.
For simplicity, Android groups all actual screen densities into four generalized densities: low, medium, high, and extra high.
low = 120dpi
med = 160dpi
high = 240dpi
xhi = 320dpi
So the Galaxy SII, with a real density of 218, gets assigned a "high" density of 240 in dp calculations. Thus the width of the screen in dp is 480/240*160 = 320.
This sucks, I agree. But it's how it works.
http://developer.android.com/guide/practices/screens_support.html

Related

What exactly is the difference between physical density and physical density of a device?

I have created a function to calculate diagonal screen size based on the resolution and pixel density. viz-
def find_display_size(d):
width=float(720);
height=float(1280);
dens=float(294);
wi=float(width)/(dens);
hi=float(height)/(dens);
x = math.pow(wi,2);
y = math.pow(hi,2);
screenInches = math.sqrt(x+y);
diagScreenSizeRoundedoff = round(screenInches)
logger.info("screenInches "+str(screenInches),also_console=True)
logger.info("diagScreenSizeRoundedoff"+str(diagScreenSizeRoundedoff),also_console=True)
I want to fetch the information (resolution & pixel density) using adb shell.
When I am trying this command-
$adb shell wm density
Result-
Physical density: 320
The result I am getting is the physical density of a device(=320), however the pixel density of the particular device is (~294). Curious to know what exactly is the difference between these two, also how I can find the pixel density using adb commands which is ~294 in this case.
PS- The device I am working on is- MOTO XT1068
Android is fitting your device to one of group mdpi, hdpi, xhdpi etc. which have fixed density set. e.g. devices with 290-340 dpi will use 320 value, xxhdpi will be 480, mdpi only 160. This density is used for fetching data from resources (dimens, for calculating xml drawables, resizing drawable when is only in mhdpi folder, but device is xxdpi etc.) More densities and about topic in HERE
Screen density
The quantity of pixels within a physical area of the screen; usually referred to as dpi (dots per inch). For example, a "low" density screen has fewer pixels within a given physical area, compared to a "normal" or "high" density screen.
For simplicity, Android groups all actual screen densities into six generalized densities: low, medium, high, extra-high, extra-extra-high, and extra-extra-extra-high.

Smallest Width for Galaxy S and Galaxy S2

I'm developing an Android Widget and need to differentiate between Galaxy S and Galaxy S2.
I almost read everything about Screen sizes and densities articles.
And I need, of course, to use the new qualifiers with the new qualifier Smallest Width.
My problem is, that the sw320dp qualifier match for Galaxy S and also for Galaxy S2.
But I need another layout for Galaxy S2, but cant find the right qualifier for it.
Definition of Galaxy S, Density 233
Screen Size in Pixels: 480 Pixel x 800 Pixel
Screen Size in dp: 329dp x 549dp (cause 1dp = 1pixel/(density/160)
-> so the qualifier sw320dp must match here. and yes it does
Definition of Galaxy S II, Density 218
Screen Size in Pixels: 480 Pixel x 800 Pixel
Screen Size in dp: 352dp x 587dp (cause 1dp = 1pixel/(density/160)
-> so the qualifier sw340dp must match here, but NO it doesnt
(Tested in emulator and on real device)
The drawables are not the problem, but my layout, especially the height and text sizes are different on these devices, so I really need a specific layout for them.
Anyone has an idea or more experience with it?
Screen density, as defined by the reference material is:
The quantity of pixels within a physical area of the screen; usually referred to as dpi (dots per inch). For example, a "low" density screen has fewer pixels within a given physical area, compared to a "normal" or "high" density screen.
For simplicity, Android groups all actual screen densities into four generalized densities: low, medium, high, and extra high.
low = 120dpi
med = 160dpi
high = 240dpi
xhi = 320dpi
So the Galaxy SII, with a real density of 218, gets assigned a "high" density of 240 in dp calculations. Thus the width of the screen in dp is 480/240*160 = 320.
This sucks, I agree. But it's how it works.
http://developer.android.com/guide/practices/screens_support.html

Declaring Tablet Layouts for Android 3.2 - mild confusion

According to this guide's chapter px = dp * (dpi / 160) and to that layout specifications change from buckets(physical size in inches) to "dp" units so that:
320dp: a typical phone screen (240x320 ldpi, 320x480 mdpi, 480x800
hdpi, etc).
480dp: a tweener tablet like the Streak (480x800 mdpi).
600dp: a 7” tablet (600x1024 mdpi).
720dp: a 10” tablet (720x1280 mdpi, 800x1280 mdpi, etc).
Since "dp" values depend on "px" and "dpi" values so that: dp = px / (dpi / 160) - isn't it possible that a phone device with high resolution will take a layout from w600dp folder?
For instance: Samsung galaxy s3 dp = 1280 / (303 / 160) = 670; Samsung galaxy s2 dp = 800 / (217 / 160) = 592. So, galaxy s3 is going to take "tablet-oriented" template, right. Is it okay, especially if a tablet version contains more elements and overall interface ergonomics gonna suffer from the tablet layout in case of s3 ? Why don't just stick to display buckets ?
You're probably going to recommend using "sw" key but I just want make sure that those "dp" units actually relate to sizes so that tablet-oriented template won't be shown on phone devices.
So, would you mind sharing your practical knowledge on applying the new approach ?
Thanks
A dp or dip is a (screen) Density Independant Pixel. The confusing part about that is that is mentions pixel. It is actually a unit similar to a centimeter or inch.
Each device defines a dpi bucket for it's screen, for example mdpi which is 160dpi. That means that you find 160 pixel across one inch on the screen. It's not 100% accurate since physical screens are usually not exactly 160 dpi (or whatever value that is defined for the bucket). But it's a value that comes close.
That means that 160dp on a perfect 160dpi screen are actually 160 pixel. On a device with a perfect xhdpi (=320dpi) screen those 160dp would be 320 pixel. (px = 160dp * (320dpi / 160))
To work with dp don't think in pixel. Think in inch, milimeter or what unit you prefer. The recommended 48dp rythm for UI elements for example explains that
On average, 48dp translate to a physical size of about 9mm (with some variability)
To approximate that: 50dp = one finger wide.
That hopefully explains why a typical 320dp phone screen is always smaller than a 720dp tablet screen although the smaller screen can have more pixel than the larger. The dpi / pixel thing is already factored into dp.
How to do different layout for different screensizes? (i.e. phone vs table)
Use the screen size buckets (small, ..., xlarge) for the layout. They represent physical small to large screens. You don't need sw600dp etc unless you need to adjust very special cases.
The different dpi buckets should only concern you for images. E.g. high resolution images for high resolution screens of any size in the drawable-hdpi folder.
The S3 does not have a density of 160.

Android layouts for same density different diagonal length

I have 2 different android phones. The details are
nexus s: 480 x 800 pixels, 4.0 inches (~233 ppi pixel density)
desire s: 480 x 800 pixels, 3.70 inches (~252 ppi pixel density)
Now I have my layout folders as layout_hdpi and layout_xhdpi. Now both these phones are classes as hdpi phones. I have a controls with a padding of 5dip to the left and the right. But on these phones the 5dip translates to different widths hence the border on one phone is fatter then on the second phone. Increasing one also increases the other. Can someone help me please?
for different screen sizes use relative-layouts.. it will not cause the problem of different width on different phones
First of all layout_hdpi and layout_xhdpi should be declared as layout-hdpi and layout-xhdpi.
Secondly, HDPI refers to the range 161–240(ppi). So your Nexus phone is eligible for the HDPI qualifier, but your Desire S is eligible for XHDPI qualifier, because the range of xhdpi is 241–319.

Emulator HDPI vs. MDPI vs. LDPI

Starting android emulators with the same resolution of 480x800 at different DPIs (120, 160, 240), I would think that the screen with the highest DPI would have the smallest interface elements (images, buttons, etc) and the one with the lowest DPI would have the largest. But exactly the opposite is true. I've included a screen shot to demonstrate what I mean.
My emulator settings are:
HDPI:
Skin resolution: 480x800
Abstracted LCD Density: 240
MDPI:
Skin resolution: 480x800
Abstracted LCD Density: 160
LDPI:
Skin resolution: 480x800
Abstracted LCD Density: 120
I started each of the emulators with the following settings:
Scale display to real size
Screen size: 5 inches
Monitor dpi: 105
Scale: 0.56
Am I doing something wrong, or is this the expected result? If it is, why does it behave in this way? If I do the equivalent in Photoshop (view for print option), I get the exact opposite and correct results.
The problem turns out to be simple math. If we take the formula for calculating DPI as
dpi = sqrt(height^2 + width^2)/(screen size in inches)
it becomes apparent that you cannot choose all three components when running an emulator -- only two, and android will calculate the missing component.
From my original question above, I was specifying a constant resolution (480x800) and a constant screen size (5 inches). But 480x800 always produces a DPI of roughly 186 dpi. So forcing the DPI to be different in each of these cases confused the Android emulator, and I think it discarded my specified original resolution and calculated its own.
This is expected. Android increases the default font size in anticipation of this higher DPI. The goal is so that at a certain physical screen size (say 3") the font has the same physical size, no matter its resolution. Higher density displays have smaller pixels, so when setting the DPI setting higher Android needs use a bigger font to appear the same size relative the screen.

Categories

Resources