【任务面板html源码】【表情识别源码】【rxjava源码分析】displaymetrics源码
1.Androidä¸dipï¼dpï¼spï¼ptåpxçåºå«
2.Androidä¸dipï¼dpï¼spï¼ptåpxçåºå«è¯¦è§£
Androidä¸dipï¼dpï¼spï¼ptåpxçåºå«
1ãæ¦è¿°
è¿å»ï¼ç¨åºåé常
以åç´ ä¸ºåä½è®¾è®¡è®¡ç®æºç¨æ·çé¢ãä¾å¦ï¼å¾ç大å°ä¸ºÃåç´ ãè¿æ ·å¤ççé®é¢å¨äºï¼å¦æå¨ä¸ä¸ªæ¯è±å¯¸ç¹æ°ï¼dpiï¼æ´é«çæ°æ¾ç¤ºå¨ä¸è¿è¡è¯¥ç¨åºï¼å
ç¨æ·çé¢ä¼æ¾å¾å¾å°ãå¨æäºæ åµä¸ï¼ç¨æ·çé¢å¯è½ä¼å°å°é¾ä»¥çæ¸ å 容ãç±æ¤æ们éç¨ä¸å辨çæ å ³ç度éåä½æ¥å¼åç¨åºå°±è½å¤è§£å³è¿ä¸ªé®é¢ãAndroid
åºç¨å¼åæ¯æä¸åç度éåä½ã
2ã度éåä½å«ä¹
dip: device independent pixels(设å¤ç¬ç«åç´ ). ä¸å设å¤æä¸åçæ¾ç¤ºææ,源码任务面板html源码è¿ä¸ªå设å¤ç¡¬ä»¶æå ³ï¼ä¸è¬æ们为äºæ¯æWVGAãHVGAåQVGA æ¨è使ç¨è¿ä¸ªï¼ä¸ä¾èµåç´ ã
dp: dipæ¯ä¸æ ·ç
px: pixels(åç´ ). ä¸å设å¤æ¾ç¤ºææç¸åï¼ä¸è¬æ们HVGA代表xåç´ ï¼è¿ä¸ªç¨çæ¯è¾å¤ã
pt: pointï¼æ¯ä¸ä¸ªæ åçé¿åº¦åä½ï¼1ptï¼1/è±å¯¸ï¼ç¨äºå°å·ä¸ï¼é常ç®åæç¨ï¼
sp: scaled pixels(æ¾å¤§åç´ ). 主è¦ç¨äºåä½æ¾ç¤ºbest for textsizeã
inï¼è±å¯¸ï¼ï¼é¿åº¦åä½ã
mmï¼æ¯«ç±³ï¼ï¼é¿åº¦åä½ã
3ã度éåä½çæ¢ç®å ¬å¼
å¨androidæºç å TypedValue.javaä¸ï¼æ们çå¦ä¸å½æ°ï¼
å¤å¶ä»£ç 代ç å¦ä¸:
public static float applyDimension(int unit, float value,
DisplayMetrics metrics)
{
switch (unit) {
case COMPLEX_UNIT_PX:
return value;
case COMPLEX_UNIT_DIP:
return value * metrics.density;
case COMPLEX_UNIT_SP:
return value * metrics.scaledDensity;
case COMPLEX_UNIT_PT:
return value * metrics.xdpi * (1.0f/);
case COMPLEX_UNIT_IN:
return value * metrics.xdpi;
case COMPLEX_UNIT_MM:
return value * metrics.xdpi * (1.0f/.4f);
}
return 0;
}
该å½æ°åè½ï¼æ¯æååä½æ¢ç®ä¸ºåç´ ã
metrics.densityï¼é»è®¤å¼ä¸ºDENSITY_DEVICE / (float) DENSITY_DEFAULT;
metrics.scaledDensityï¼é»è®¤å¼ä¸ºDENSITY_DEVICE / (float) DENSITY_DEFAULT;
metrics.xdpiï¼é»è®¤å¼ä¸ºDENSITY_DEVICE;
DENSITY_DEVICEï¼ä¸ºå±å¹å¯åº¦
DENSITY_DEFAULTï¼é»è®¤å¼ä¸º
4ãå±å¹å¯åº¦ï¼è¡¨ç¤ºæ¯è±å¯¸æå¤å°ä¸ªæ¾ç¤ºç¹ï¼ä¸å辨çæ¯ä¸¤ä¸ªä¸åçæ¦å¿µã
Android主è¦æ以ä¸å ç§å±ï¼å¦ä¸è¡¨
å¹
Tyep
宽度
Pixels
é«åº¦
Pixels
尺寸
Range(inches)
å±å¹å¯åº¦
QVGA
2.6-3.0
low
WQVGA
3.2-3.5
low
FWQVGA
3.5-3.8
low
HVGA
3.0-3.5
Medium
WVGA
3.3-4.0
High
FWVGA
3.5-4.0
High
WVGA
4.8-5.5
Medium
FWVGA
5.0-5.8
Medium
å¤æ³¨
ç®åandroidé»è®¤çlow= ï¼Medium =ï¼ High =
5ã综ä¸æè¿°
æ®px = dip * density / ï¼åå½å±å¹å¯åº¦ä¸ºæ¶ï¼px = dip
æ ¹æ® google ç建议ï¼TextView çåå·æå¥½ä½¿ç¨ sp ååä½ï¼èä¸æ¥çTextViewçæºç å¯ç¥Androidé»è®¤ä½¿ç¨spä½ä¸ºåå·åä½ãå°dipä½ä¸ºå ¶ä»å ç´ çåä½ã
èµææ¥æºï¼/question/.html?entry=qb_ihome_tag
Androidä¸dipï¼dpï¼spï¼ptåpxçåºå«è¯¦è§£
ãdip: device independent pixels(设å¤ç¬ç«åç´ ). ä¸è¬æ们为äºæ¯æå¤ç§å辨çå¦WVGAãHVGAåQVGA æ¨è使ç¨è¿ä¸ªï¼ä¸ä¾èµåç´ ã
ããdp: dipæ¯ä¸æ ·çï¼è°·æå®æ¹æ¨è使ç¨è¿ä¸ª
ããpx: pixels(åç´ ). ä¸å设å¤æ¾ç¤ºææç¸åï¼ä¸è¬æ们HVGA代表xåç´ ï¼è¿ä¸ªç¨çæ¯è¾å°ãpt: pointï¼æ¯ä¸ä¸ªæ åçé¿åº¦åä½ï¼1ptï¼1/è±å¯¸ï¼ç¨äºå°å·ä¸ï¼é常ç®åæç¨ï¼
ããsp: scaled pixels(æ¾å¤§åç´ ). 主è¦ç¨äºåä½æ¾ç¤ºbest for textsizeã
ãã3ã度éåä½çæ¢ç®å ¬å¼
ããå¨androidæºç å TypedValue.javaä¸ï¼æ们çå¦ä¸å½æ°ï¼
ãã代ç å¦ä¸:
ããpublic static float applyDimension(int unit, float value,
ããDisplayMetrics metrics)
ãã{
ããswitch (unit) {
ããcase COMPLEX_UNIT_PX:
ããreturn value;
ããcase COMPLEX_UNIT_DIP:
ããreturn value * metrics.density;
ããcase COMPLEX_UNIT_SP:
ããreturn value * metrics.scaledDensity;
ããcase COMPLEX_UNIT_PT:
ããreturn value * metrics.xdpi * (1.0f/);
ããcase COMPLEX_UNIT_IN:
ããreturn value * metrics.xdpi;
ããcase COMPLEX_UNIT_MM:
ããreturn value * metrics.xdpi * (1.0f/.4f);
ãã}
ããreturn 0;
ãã}
ãã该å½æ°åè½ï¼æ¯æååä½æ¢ç®ä¸ºåç´ ã
ããmetrics.densityï¼é»è®¤å¼ä¸ºDENSITY_DEVICE / (float) DENSITY_DEFAULT;
ããmetrics.scaledDensityï¼é»è®¤å¼ä¸ºDENSITY_DEVICE / (float) DENSITY_DEFAULT;
ããmetrics.xdpiï¼é»è®¤å¼ä¸ºDENSITY_DEVICE;
ããDENSITY_DEVICEï¼ä¸ºå±å¹å¯åº¦
ããDENSITY_DEFAULTï¼é»è®¤å¼ä¸º