我的程序初始化是設置全屏顯示,即(不顯示狀態欄與標題欄)
nCreat或onResume獲得屏幕寬高:
Rect mRect = new Rect();
Window win = DisplayColor.this.getWindow();win.getDecorView().getWindowVisibleDisplayFrame(mRect);
int height = mRect.getBottom();
int width =mRect.getRight();
寬高是不包含標題欄、狀態欄的高度(w:1280,h:752)。
由於程序是畫圖顯示界面。
在繪圖OnDraw函數裏獲取屏幕寬高就是屏幕物理真正的寬高了(w:1280,h:800)。
同樣功能:
View v = getWindow().findViewById(Window.ID_ANDROID_CONTENT);
int height = v.getBottom();
int width = v.getRight(); (w:1280,h:800)。
而
在繪圖OnDraw函數裏獲取寬高:
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
int width = dm.widthPixels;
height = dm.heightPixels
是(w:1280,h:752)想來DisplayMetrics它是隻獲取不包含標題欄、狀態欄的屏幕寬度高度。