1.屏幕尺寸,源代码如下:
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
int
screenWidth=metrics.widthPixels;
//屏幕宽度
int
.screenHeight=metrics.heightPixels;
//屏幕高度
2.获取标题栏、状态栏高度:
Rect rect =
new
Rect();
Window win = this .getWindow();
win.getDecorView().getWindowVisibleDisplayFrame(rect);
int statusBarHeight = rect.top;
int contentViewTop = win.findViewById(Window.ID_ANDROID_CONTENT).getTop();
int titleBarHeight = contentViewTop - Variable.statusBarHeight;
Window win = this .getWindow();
win.getDecorView().getWindowVisibleDisplayFrame(rect);
int statusBarHeight = rect.top;
int contentViewTop = win.findViewById(Window.ID_ANDROID_CONTENT).getTop();
int titleBarHeight = contentViewTop - Variable.statusBarHeight;