1.通过WindowManager获取
private DisplayMetrics dm;//屏幕分辨率容器
dm = new DisplayMetrics();
this.getWindowManager().getDefaultDisplay().getMetrics(dm);
int width = dm.widthPixels;
int height = dm.heightPixels;
2.通过Resources获取
DisplayMetrics dm = getResources().getDisplayMetrics();
int width = dm.widthPixels;
int height= dm.heightPixels;
3.获取屏幕的默认分辨率
Display display = getWindowManager().getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
网友评论