2012-03-26 92 views
0

我需要一種方式來說,如果設備是LDPI或MDPI或HDPI設置HTML字體大小爲x。 e.g根據屏幕密度的Android的HTML字體大小

if (ldpi){ 
htmlString.append("<br><p align='center'><font color='Yellow' size='5'>"); 
} 
else if (mdpi){ 
htmlString.append("<br><p align='center'><font color='Yellow' size='6'>"); 
} 
else if (hdpi){ 
htmlString.append("<br><p align='center'><font color='Yellow' size='7'>"); 
} 

任何幫助,將不勝感激

回答

1

參考:http://developer.android.com/reference/android/util/DisplayMetrics.html

,你可以得到這樣的dpi值;

DisplayMetrics metrics = new DisplayMetrics(); 
getWindowManager().getDefaultDisplay().getMetrics(metrics); 

並比較density屬性與常量;

int DENSITY_DEFAULT The reference density used throughout the system. 
int DENSITY_HIGH Standard quantized DPI for high-density screens. 
int DENSITY_LOW Standard quantized DPI for low-density screens. 
int DENSITY_MEDIUM Standard quantized DPI for medium-density screens. 
int DENSITY_TV Standard quantized DPI for 720p TV screens. 
int DENSITY_XHIGH 
+0

感謝您的幫助 – 2012-03-26 14:58:46

相關問題