方法一:
WindowManager windowManager = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
DisplayMetrics displayMetrics = new DisplayMetrics();
windowManager.getDefaultDisplay().getMetrics(displayMetrics);
int width = displayMetrics.widthPixels;
int?height = displayMetrics.heightPixels;
方法二:
int?width?=?getResources().getDisplayMetrics().widthPixels
int?height?=?getResources().getDisplayMetrics().heightPixels