teoREtik
teoREtik

Reputation: 7916

How does density value calculate in android

Can anybody explain me what formula android use to calculate screen density?

Upvotes: 16

Views: 22379

Answers (4)

sandes
sandes

Reputation: 2277

To calculate screen density, you can use this equation:

Screen density = Screen width (or height) in pixels / Screen width (or height) in inches

Upvotes: 0

Hari Kumar
Hari Kumar

Reputation: 426

Density can be calculated by the following formula:

Density = sqrt((wp * wp) + (hp * hp)) / di

Where:

wp is width resolution in pixels,

hp is height resolution in pixels, and

di is diagonal size in inches.

Upvotes: 41

Labeeb Panampullan
Labeeb Panampullan

Reputation: 34833

int pixel = 120;
final float scale = getResources().getDisplayMetrics().density;
int dip = (int) (pixel* scale + 0.5f);

Refer this following links

Upvotes: 1

Ted Hopp
Ted Hopp

Reputation: 234857

The formula is actual-dpi / 160. (Everything is scaled to 160 dpi.)

Upvotes: 6

Related Questions