Different DPI Screen Resolutions (PIXELS) - android

i just wanted to know. i've read about this DPIs and i wandered all of the varieties. since i am new to this, i need some knowledge and i hope someone can help me out. so far i've seen LDPI, MDPI, HDPI, XHDPI, XXHDPI, XXXHDPI.
is there any other DPI variety other than this. and what is their respective resolutions ?. like as for qHD = 960 x 540 etc etc. i hope you understand guys, thanks.
please forgive me if my grammar is a little crappy, as english is not my native language

Android supports different screen resolutions
ldpi (low) ~120dpi
mdpi (medium) ~160dpi
hdpi (high) ~240dpi
xhdpi (extra-high) ~320dpi
xxhdpi (extra-extra-high) ~480dpi
xxxhdpi (extra-extra-extra-high) ~640dpi
1 dpi = 1 design independent pixel
ldpi device have 120 pixels in 1 inch size.
same for other densities...
we as programmer should use this conversion formulae :
pixel = dp * (density / 160)
so 240 dpi hdpi device's 1 dp will have = 1 * (240/160) = 3/2 = 1.5 pixels
and 240 dpi xxhdpi device's 1 dp will have = 1 * (480/160) = 3 pixels
Using this 1.5 and 3 pixels knowledge, programmer can design layouts for different densities

Related

How to calculate dp for LDPI,MDPI,HDPI,XXHDPI,XXXHDPI in android

i have screen which is deisgned in XHDPI .
I have to convert all padding ,margin value of dp into LDPI,MDPI,HDPI,XXHDPI,XXXHDPI
Can any one please suggest me how i will calculate dp value for follwing screen suppose i have paddingTop in xhdpi is 56dp then what value we have give for ldpi,mdpi, xxhdpi and xxxhdpi
please suggest me.
Density-independent pixel (dp)
A virtual pixel unit that you should use when defining UI layout, to express layout dimensions or position in a density-independent way.
The density-independent pixel is equivalent to one physical pixel on a 160 dpi screen, which is the baseline density assumed by the system for a "medium" density screen. At runtime, the system transparently handles any scaling of the dp units, as necessary, based on the actual density of the screen in use. The conversion of dp units to screen pixels is simple: px = dp * (dpi / 160). For example, on a 240 dpi screen, 1 dp equals 1.5 physical pixels. You should always use dp units when defining your application's UI, to ensure proper display of your UI on screens with different densities.
If you want to know what's 56dp in xhdpi, that's 56dp in ldpi, mdpi, hdpi, xxhdpi, xxxhdpi as well - as the definition says, it's density-independent pixels.
When you work with a design, you want to know one thing:
What's the baseline scale for the design?
Some quick answers: It's usually 1x, 2x or in rare cases 3x
Android defines the following densities:
ldpi (low) ~120dpi
mdpi (medium) ~160dpi
hdpi (high) ~240dpi
xhdpi (extra-high) ~320dpi
xxhdpi (extra-extra-high) ~480dpi
xxxhdpi (extra-extra-extra-high) ~640dpi
There are some rare cases in-between, like tvdpi, but in 99% of the cases you can just simply ignore those.
When designers say 1x, they usually refer to mdpi, 2x (or retina) refers to xhdpi and 3x design is done in xxhdpi.
Once you know the baseline, you know how to translate the pixel values from the design document to dip (density-independent pixel).
The formula is quite simple, but if you doubt yourself, feel free to try one of the online converter tools:
https://pixplicity.com/dp-px-converter
http://angrytools.com/android/pixelcalc/
The formula is as follows: dp = px / (dpi / 160) where dpi is the current screen density and px is the value in the base (1x) density.
Or the other way around.
Also, remember to read the Best Practices from the Android Developers page!
If you still end up using px in your dimensions file which are not recommended, please take a look at this answer to know how to create different values folder for different screens.

Should we use the exactly DPI number to implement for multiple screen size?

I know we have some standard of DPI that we can use it for support multiple screen size in an like :
ldpi (low) ~120dpi
mdpi (medium) ~160dpi
hdpi (high) ~240dpi
xhdpi (extra-high) ~320dpi
xxhdpi (extra-extra-high) ~480dpi
xxxhdpi (extra-extra-extra-high) ~640dpi
But when I calculate for some real device, e.g. LG G3 - it has DPI is 538.
So my question is do we need to use that exactly DPI number for scale the image,... or just let it be one of xxhdpi (480dpi) or xxxhdpi (640dpi).
For my opinion, I think you shouldn't care about information dpi of devices. You should only focus to provide images, size (dp,sp) etc for some type of 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
=========================================================================
Example:
As you maybe known that 1 px = dp (dpi/160)
So if you have an image with size is 32 x 32 px on screen 160 dpi. It's mean your image get size 32 x 32 dp.
Now you want to scale it on xxhdpi (extra-extra-high) ~480dpi.
On xxhdpi (extra-extra-high) ~480dpi : 1 px = dp(480/160) = 3dp
Then you only need to provide another image with size 32*3 x 32*3 px = 96 x 96 px
You just have to provide the right assets and android will take care of the rest. You can check the documentation for more details.
The Android system helps your application achieve density independence in two ways:
The system scales dp units as appropriate for the current screen density
The system scales drawable resources to the appropriate size, based on the current screen density, if necessary
So in your case its better to provide both the assets. At runtime, the system uses the appropriate resources for your application, based on the generalized size or density of the current device screen.

android relationship between mdpi, hdpi, xhdpi, xxhdpi how to calculate

android image size different mdpi, hdpi, xhdpi, xxhdpi ? i have a mdpi image 20*20 how to measure hdpi, xhdpi, xxhdpi how to make other resolution image
different screen sizes due to Android having set standard size ?
Here is the scale factor list for each density:
ldpi = 0.75x
mdpi = 1.0x
hdpi = 1.5x
xhdpi = 2.0x
xxhdpi = 3.0x
xxxhdpi = 4.0x
So for example, if your mdpi image size is 20x20 then xhdpi size should be 40x40
you can use the following chart
mdpi 20 * 20 pixels
hdpi (mdpi * 1.5) 30 * 30 pixels
xhdpi (mdpi * 2) 40 * 40 pixels
xxhdpi (mdpi * 3) 60 * 60 pixels

Android - PX to DP - Wrong height of layout

I am giving a layout height as 64dp in layout file and observed the mismatch in calculated and actual pixel height.
HDPI device - Calculated height - 96 pixels, Actual height: 102 pixels
XXHDPI Device - Calculated height - 192 pixels, Actual height: 204 pixels
Any one can help me understand the difference in calculated and actual height.
mdpi, hdpi, xhdpi etc are "generalized densities". That is, dpi groups or ranges.
From Android guide:
For example two devices can have dpi values of 310 and 320 dpi respectively and fall in same group: xhdpi.
The calculations done by device code are using exact dpi value. While calculations based on dpi groups assume the following:
ldpi (low) ~120dpi
mdpi (medium) ~160dpi
hdpi (high) ~240dpi
xhdpi (extra-high) ~320dpi
xxhdpi (extra-extra-high) ~480dpi
xxxhdpi (extra-extra-extra-high) ~640dpi
Update:
The following code:
int widthDp = 160;
Log.i("TEST", "Actual DPI: " + getResources().getDisplayMetrics().xdpi);
float widthDevice = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,widthDp,getResources().getDisplayMetrics());
Log.i("TEST", widthDp + " dip in pixels on device: " + widthDevice);
When run on two hdpi devices:
213 DPI device:
2164-2164/com.example.android.dpitest I/TEST﹕ Actual DPI: 213.0
2164-2164/com.example.android.dpitest I/TEST﹕ 160 dip in pixels on device: 213.0
And 240 DPI device:
2852-2852/com.example.android.dpitest I/TEST﹕ Actual DPI: 240.0
2852-2852/com.example.android.dpitest I/TEST﹕ 160 dip in pixels on device: 240.0

Screen size and dpi of bitmaps

I found two approximations of how developer should support bitmaps for different screen sizes. One is this:
ldpi low density 120 dpi
mdpi medium density 160 dpi
hdpi high density 240 dpi
xhdpi extra high density 320 dpi
The other is this:
xhdpi: 2.0
hdpi: 1.5
mdpi: 1.0 (baseline)
ldpi: 0.75
This means that if you generate a 200x200 image for xhdpi devices, you
should generate the same resource in 150x150 for hdpi, 100x100 for
mdpi and finally a 75x75 image for ldpi devices
Does it mean that If I take as a baseline 640x360, I have to make following 4 groups of images:
1) ldpi - size 480x270 pixels and density 120 dpi
2) mdpi - size 640x360 pixels and density 160 dpi
3) hdpi - size 960x540 pixels and density 240 dpi
4) xhdpi - size 1280x720 pixels and density 320 dpi
You are misunderstanding.
The documentation is not saying different things. The second part you reference is telling you how much bigger an image is in relation to the base density of mdpi
e.g xhdpi fits 2x the amount of horizontal and vertical pixels into the same space that mdpi would.
mdpi = 160 dpi (scale factor 1)
xhdpi = 320 dpi (x2 twice as dense as mdpi therefore an image in this folder needs to be twice as high and twice as wide as its mdpi counterpart to appear the same size on an xhdpi screen)

Categories

Resources