int screenWidth;
int screenHeight;
float density;//屏幕密度
//1、用WindowManager获得屏幕的宽和高
WindowManager wn=this.getWindowManager();
Display dis= wn.getDefaultDisplay();
screenWidth=dis.getWidth();
screenHeight=dis.getHeight();
//2、用DisplayMetrics获得屏幕的宽和高
DisplayMetrics dm=new DisplayMetrics();
this.getWindowManager().getDefaultDisplay().getMetrics(dm);
screenWidth=dm.widthPixels;
screenHeight=dm.heightPixels;
density=dm.density;
//3
DisplayMetrics dmm=this.getResources().getDisplayMetrics();
screenWidth=dmm.widthPixels;
screenHeight=dmm.heightPixels;
density=dmm.density;
android中的Display 与 DisplayMetrics
最新推荐文章于 2024-03-20 17:57:17 发布