新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > 屏幕單位 密度 分辨率區(qū)分

屏幕單位 密度 分辨率區(qū)分

作者: 時間:2016-09-12 來源:網(wǎng)絡(luò) 收藏

1、概念理解

本文引用地址:http://butianyuan.cn/article/201609/304714.htm

術(shù)語

說明

備注

Screen size(屏幕尺寸)

指的是手機實際的物理尺寸,比如常用的2.8英寸,3.2英寸,3.5英寸,3.7英寸

摩托羅拉milestone手機是3.7英寸

Aspect Ratio(寬高比率)

指的是實際的物理尺寸寬高比率,分為long和nolong

Milestone是16:9,屬于long

Resolution(分辨率)

和電腦的分辨率概念一樣,指手機屏幕縱、橫方向像素個數(shù)

Milestone是854*480

DPI(dot per inch)

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

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

Density(密度)

單位英寸中的像素數(shù)量,resolution/Screen size可以反映出手機密度

一般分為低、中、高密度

Density-independent pixel (dip)獨立像素

指的是邏輯密度計算單位,dip和具體像素值的對應(yīng)公式是dip/pixel=dpi值/160

頁面布局的基本單位

2、屏幕單位區(qū)別

1)dip:設(shè)備獨立像素,與屏幕密度有關(guān)

2)dp:和dip是一樣的

3)px:pixels(像素),這是絕對像素,是多少就永遠是多少不會改變

4)sp:scaled pixels(放大像素). 主要用于字體顯示best for textsize

結(jié)論:根據(jù)google的推薦,像素統(tǒng)一使用dip,字體統(tǒng)一使用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);

}



關(guān)鍵詞:

評論


相關(guān)推薦

技術(shù)專區(qū)

關(guān)閉