1、WindowManager wm = (WindowManager) getContext()
.getSystemService(Context.WINDOW_SERVICE);
int width = wm.getDefaultDisplay().getWidth();
int height = wm.getDefaultDisplay().getHeight();
簡寫爲:
int w = ((WindowManager)getApplicationContext().getSystemService.(Context.WINDOW_SERVICE)).getDefaultDisplay().getWidth();
或者:
int w = ((WindowManager)context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getWidth();
或者:
int w = ((WindowManager)this.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getWidth();
2、WindowManager wm = this.getWindowManager();
int width = wm.getDefaultDisplay().getWidth();
int height = wm.getDefaultDisplay().getHeight();
簡寫爲:
int w = this.getWindowManager().getDefaultDisplay().getWidth();
或者:
int w = getApplicationContext().getWindowManager().getDefaultDisplay().getWidth();