当前位置:首页 > android 获得屏幕宽度与高度

android 获得屏幕宽度与高度

点击次数:2946  更新日期:2018-09-07

android 获得屏幕宽度与高度

方法一:

WindowManager manager = this.getWindowManager();

DisplayMetrics outMetrics = new DisplayMetrics();

manager.getDefaultDisplay().getMetrics(outMetrics);

int width = outMetrics.widthPixels;

int height = outMetrics.heightPixels;

方法二:


Resources resources = this.getResources();

DisplayMetrics dm = resources.getDisplayMetrics();

float density = dm.density;

int width = dm.widthPixels;

int height = dm.heightPixels;