1.Androidä¸dipï¼dpï¼spï¼ptåpxçåºå«
Androidä¸dipï¼dpï¼spï¼ptåpxçåºå«
Androidä¸dipãdpãspãptåpxçåºå«
1ãæ¦è¿°
è¿å»ï¼ç¨åºåé常以åç´ ä¸ºåä½è®¾è®¡è®¡ç®æºç¨æ·çé¢ãä¾å¦ï¼å¾ç大å°ä¸ºÃåç´ ãè¿æ ·å¤ççé®é¢å¨äºï¼å¦æå¨ä¸ä¸ªæ¯è±å¯¸ç¹æ°ï¼dpiï¼æ´é«çæ°æ¾ç¤ºå¨ä¸è¿è¡è¯¥ç¨åºï¼åç¨æ·çé¢ä¼æ¾å¾å¾å°ãå¨æäºæ åµä¸ï¼ç¨æ·çé¢å¯è½ä¼å°å°é¾ä»¥çæ¸ å 容ãç±æ¤æ们éç¨ä¸å辨çæ å ³ç度éåä½æ¥å¼åç¨åºå°±è½å¤è§£å³è¿ä¸ªé®é¢ãAndroidåºç¨å¼åæ¯æä¸åç度éåä½ã
2ã度éåä½å«ä¹
dip: device independent
pixels(设å¤ç¬ç«åç´ ). ä¸å设å¤æä¸åçæ¾ç¤ºææ,以太坊 源码è¿ä¸ªå设å¤ç¡¬ä»¶æå ³ï¼ä¸è¬æ们为äºæ¯æ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ä½ä¸ºå ¶ä»å ç´ çåä½ã
url:blogs.com/archive////Android-dip-dp-sp-pt-px.html