I have 2 questions about the "DPI" term.
1st, i googled this term, someone said that it means dots per inch. and we can use follow formula to canculate the screen dpi:
dpi = radical(screen_width_pixel^2+screen_height_pixel^2)/screen_inchs
Now, i have an android tv, i found that my tv resolution is 1920*1080, and the dpi is 240, the tv size is 50 inch. But if i use above formula to calculate the dpi, i will get the dpi value is 40, i don't know why? is above formula ppi formula?
2nd, i found that the dpi value is in the build.prop->ro.sf.lcd_density=240, i don't know why the manfacturer set this value, in other words, what is this value based on, why not setting 320 or other values? They user above farmula to get the value and set it?
Thanks a lot!
I have been researching answer to your question for last one day, and reached some conclusions -
1.
PPI is pixels per inch, purely mathematical. i.e. - it calculate number of pixels per inch.
DP - Device Independent Pixels AKA dots -> i.e. android system defines a virtual pixel so that it could compare devices with different pixel densities. You know baseline is 160 DPi (160 dots per inch), so any MDPI device has a virtual grid which contains 160 DP per inch, while a device which is HDPI has same grid but it will contain 240 DP per inch. (Note that number of pixels one dot/Device independent Pixel may contain varies, depending on the size of device.)
here comes your answers-
a) DPi is system defined, all you can calculate is number of DP in one inch, which in your case sums up to - 1920*160/240 =1280 DPs in height, 1080*160/240 = 720 DPs in width), what you calculated is PPi.
b) manufacturer set it so that you could know how much you need to resize your image. Suppose an image which is of certain size in 160DPi, then to make this image look same size, you need to double the size of the image on 320DPi screen.
Note - I tried on my part to make you understand, if you find any problem understanding my answer, Please comment, would be happy to assist.
Reference # 1
Try this information Iuser lastly to develop and android studio screens
ldpi (low) ~ 120dpi
mdpi (medium) ~ 160dpi
hdpi (high) ~ 240dpi
xhdpi (extra-high) ~ 320dpi
xxhdpi (extra-extra-high) ~ 480dpi
xxxhdpi (extra-extra-extra-high) ~ 640dpi
-
res/values/dimens.xml(default)
res/values-ldpi/dimens.xml (240x320 and nearer resolution)
res/values-mdpi/dimens.xml (320x480 and nearer resolution)
res/values-hdpi/dimens.xml (480x800, 540x960 and nearer resolution)
res/values-xhdpi/dimens.xml (720x1280 - Samsung S3, Micromax Canvas HD, etc)
res/values-xxhdpi/dimens.xml (1080x1920 - Samsung S4, HTC one, etc)
res/values-large/dimens.xml (480x800)
-
res/values-large-mdpi/dimens.xml (600x1024)
res/values-sw600dp/dimens.xml (600x1024)
res/values-sw720dp/dimens.xml (800x1280)
res/values-xlarge-xhdpi/dimens.xml (2560x1600 - Nexus 10")
res/values-large-xhdpi/dimens.xml (1200x1920 - Nexus 7"(latest))
w600 says if width of current orientation is nearby 600
sq600 says if smallest with of device is nearby 600
Related
I want to know the screen size of an Android phone (without using code)
For example: I find that from specs someone has a device with 1080 x 1920 pixels (~445 ppi pixel density)
How would I go from here to figure out which layout his or her phone will support?
From this document, I got:
lpdi = 120 DPI
mdpi = 160 DPI
hdpi = 240 DPI
xhdpi = 320 DPI
xxhdpi = 480 DPI
xxxhdpi = 640 DPI
And this rough estimation below which seems so ridiculous.
Where does the DPI fall, if it is 215 for example?
I want to know the layout size to choose for a particular device that I don't own:
Whether the layout be should be small, medium, large, or extra large ?
There's a bit of confusion between dpi and ppi.
The correct term should be ppi, but it's dpi by convention.
So, roughly, we can assume that ppi = dpi, for our purposes.
For your reference: http://www.fastcodesign.com/3039564/the-difference-between-ppi-vs-dpi-explained-by-a-google-designer
445 ppi falls in the 480 dpi normalized bucket. 215 ppi falls in the 240 dpi normalized bucket.
I used the term "bucket" improperly: I should have said "range", to be more clear.
How would I calculate the ranges?
I'd say that the range starts from the median between (320 and 480) + 1 and ends at the median between 480 and 640.
Therefore, for the 480 "bucket", I calculate a range between 401 and 560. And 445 falls here into.
Note: it's all empyrical.
The proposed figure on the Android developers site is a poor representation of the concept.
I prefer to imagine those buckets like adjacent funnels with a "mouth" which is 160 dpi wide and an end which points to a normalized value.
Here's an image I prepared just to make it even more clear:
I have design for my project. It for Nexus 6 with resolution 1440px x 2560px and 493 ppi. My design - 1440px x 2560px.
I know that:
ldpi 120 dpi
mdpi 160 dpi
tvdpi 213 dpi
hdpi 240 dpi
xhdpi 320 dpi
xxhdpi 480 dpi
xxxhdpi 640 dpi
I have - 493 ppi. what's this? I have a button size 100x50 pixels on the design.
how many dpi need button to look as well as in the design?
Hope this helps: Getting Your Apps Ready for Nexus 6 and Nexus 9
Nexus 6
Screen
The Nexus 6 boasts an impressive 5.96” Quad HD screen display at a
resolution of 2560 x 1440 (493 ppi). This translates to ~ 730 x 410 dp
(density independent pixels).
Check your assets
It has a quantized density of 560 dpi, which falls in between the
xxhdpi and xxxhdpi primary density buckets. For the Nexus 6, the
platform will scale down xxxhdpi assets, but if those aren’t
available, then it will scale up xxhdpi assets.
EDIT:
Consider this line
2560 x 1440 (493 ppi). This translates to ~ 730 x 410 dp (density
independent pixels)
It implies the scaling factor is 2560/730 = 1440/410 ~ 3.5
For a screen of width 410 and height 730 in dp, if you want to specify a button of half the screen width in dp, the width should be 410/2 = 205 dp which translates to 717px = 205*3.5 (width in dp * scaling factor)
A button of size 100px x 50px would translate to 28 x14 dp (100/3.5 * 50/3.5) on a 410 x 730 dp screen size.
If you are genuinely concerned about proper display resolution (which it sounds like you are) then you should never rely on the generic folders. The folders are there for generalized purposes - not for customized or high value display.
You should use displayMetrics to measure the screen size and select the appropriate asset, or even do customized image scaling. There are a lot of resources around this set of properties, but essentially it allows you to address the issue you are facing: set appropriate margins, padding, resolution, layout, etc. for a highly customized display.
Here are the docs:
http://developer.android.com/reference/android/util/DisplayMetrics.html
And then some "simple" implementations of getting the metrics:
How to get screen display metrics in application class
getting the screen density programmatically in android?
For example, I'd like to show an image in screen. Here are the size and dpi:
LDPI - 0.75x 75x75 120 dpi
MDPI - Original size 100x100 160 dpi
HDPI - 1.5x 150x150 240 dpi
XHDPI - 2.0x 200x200 320 dpi
XXHDPI - 3x 300x300 480 dpi
XXXHDPI - 4.0x 400x400 640 dpi
But the display for two devices is not what I want.
The first device is 480x800, 240 dpi. The second device is 800x1280, 213 dpi.The bigger screen has lower dpi. I need some advices on how to handle this case? Thanks
What I see is that your first device is a mobile while the second is a tablet. So you can provide alternate layout files for mobile's and tablets. See supporting multiple screens for more information. For this case for mobile you can use layout-sw720dp folder and for the bigger tablet screen. As for the images your current settings above will work great.
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.
How do I know how much DPIs a device has (and thus if it's ldpi / mdpi / hdpi / xhdpi, - and screen size, which is also measured in dp - xlarge / large / normal / small - according to http://developer.android.com/guide/practices/screens_support.html)?
I know the device's resolution and diagonal size, for example:
Display TFT LCD, 3.5 in (89 mm) diagonal.
320×480 px HVGA with Gorilla Glass
16M colors
(Taken from http://en.wikipedia.org/wiki/Samsung_Galaxy_Ace)
Don't need it programmatically, just to calculate myself.
Use DPI calculator to calculate dpis, and Figure 1 in the dev docs to determine whether its ldpi, mdpi, etc.
I think DPI reffers to printers... IN your case DPI = PPI. Please correct me if i'm wrong [edit: I'm wrong :P]
'So a 1200 dpi printer uses 1200 dots of ink in every inch to make up the colours. If you were printing a 300 PPI image, then every pixel would be made up of 16 smaller ink dots (1200 DPI x 1200 DPI / 300 PPI x 300 PPI). A lower DPI would have fewer ink dots making up each pixel, which would make the colour look worse. A higher DPI would have more ink dots for each pixel and should give more accurate colour (especially under close examination).'