屏幕单位 密度 分辨率区分

1、概念理解

术语

说明

备注

Screen size(屏幕尺寸)

指的是手机实际的物理尺寸,比如常用的2.8英寸,3.2英寸,3.5英寸,3.7英寸

摩托罗拉milestone手机是3.7英寸

Aspect Ratio(宽高比率)

指的是实际的物理尺寸宽高比率,分为long和nolong

Milestone是16:9,属于long

Resolution(分辨率)

和电脑的分辨率概念一样,指手机屏幕纵、横方向像素个数

Milestone是854*480

DPI(dot per inch)

每英寸像素数,如120dpi,160dpi等,假设QVGA(320*240)分辨率的屏幕物理尺寸是(2英寸*1.5英寸),dpi=160

可以反映屏幕的清晰度,用于缩放UI的

Density(密度)

单位英寸中的像素数量,resolution/Screen size可以反映出手机密度

 一般分为低、中、高密度

Density-independent pixel (dip)独立像素

指的是逻辑密度计算单位,dip和具体像素值的对应公式是dip/pixel=dpi值/160

 页面布局的基本单位

2、屏幕单位区别

1)dip:设备独立像素,与屏幕密度有关

2)dp:和dip是一样的
3)px:pixels(像素),这是绝对像素,是多少就永远是多少不会改变
4)sp:scaled pixels(放大像素). 主要用于字体显示best for textsize

结论:根据google的推荐,像素统一使用dip,字体统一使用sp

3、dip与px换算

px=dip*屏幕密度(屏幕密度用getDisplayMetrics().density获得

 

public static int dip2px(Context context, float dipValue){ 
    final float scale = context.getResources().getDisplayMetrics().density; 
    return (int)(dipValue * scale + 0.5f); 
} 
        
public static int px2dip(Context context, float pxValue){ 
    final float scale = context.getResources().getDisplayMetrics().density; 
    return (int)(pxValue / scale + 0.5f); 
} 

 

 

 

posted @ 2012-12-23 20:20  ok_lanyan  阅读(1061)  评论(0编辑  收藏  举报