开发者

How does density value calculate in android

开发者 https://www.devze.com 2023-02-09 04:51 出处:网络
Can anybody explain me what formula android use to cal开发者_如何学JAVAculate screen density? Density can be calculated by the following formula:

Can anybody explain me what formula android use to cal开发者_如何学JAVAculate screen density?


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.


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


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

Refer this following links

  • getDisplayMetrics(), for current display metrics
  • density, This is a scaling factor for the Density Independent Pixel unit


To calculate screen density, you can use this equation:

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

0

精彩评论

暂无评论...
验证码 换一张
取 消