private void getScreenSize(){
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
int width = metrics.widthPixels;//宽度 px
int height = metrics.heightPixels;//高度 px
float density = metrics.density;//密度 0.75/1.0/1.5
int densityDpi = metrics.densityDpi;//密度dpi(120/160/240)
int screenW = (int)(width/density);//屏幕宽度(dp)
int screenH = (int)(height/density);//屏幕高度(dp)
LogUtils.i("width:"+width+" height:"+height+" density:"+density+" densityDpi:"+densityDpi+" screenW:"+screenW+" screenH:"+screenH);
}
网友评论