屏幕密度

density 密度
密度和dpi相关,dpi每英寸的点数

densityDp
{
DENSITY_LOW = 120
DENSITY_MEDIUM = 160 //默认值
DENSITY_TV = 213 //TV专用
DENSITY_HIGH = 240
DENSITY_XHIGH = 320
DENSITY_400 = 400
DENSITY_XXHIGH = 480
DENSITY_XXXHIGH = 640
}

private void getDensity() {
DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
Log.d(TAG,"Density is "+displayMetrics.density+" densityDpi is "+displayMetrics.densityDpi+" height: "+displayMetrics.heightPixels+
" width: "+displayMetrics.widthPixels);
}

对角线的长度
private void getScreenSizeOfDevice() {
DisplayMetrics dm = getResources().getDisplayMetrics();
int width=dm.widthPixels;
int height=dm.heightPixels;
double x = Math.pow(width,2);
double y = Math.pow(height,2);
double diagonal = Math.sqrt(x+y);

int dens=dm.densityDpi;
double screenInches = diagonal/(double)dens;
Log.d(TAG,"The screenInches "+screenInches);
}

posted on 2017-04-17 15:44  快扶偶去网吧  阅读(230)  评论(0编辑  收藏  举报

导航