今天总结一下,开发中常见的一些高度数据的获取。状态栏、标题栏、ActionBar或者屏幕的高度数据
工具/原料
编译工具:Eclipse
方法/步骤
1
【屏幕高度和宽度的获取】一种方法
2
另一种方法太常见的我就不贴出来了。
3
【状态栏高度】Rect frame = new Rect(); getWindow().getDecorView().getWindowVisibleDisplayFrame(frame); int statusBarHeight = frame.top;
4
【标题栏高度】int contentTop = getWindow().findViewById(Window.ID_ANDROID_CONTENT).getTop(); //statusBarHeight是上面状态栏的高度 int titleBarHeight = contentTop - statusBarHeight;
5
【ActionBar高度】int actionBarHeight = getActionBar().getHeight();
6
这个获取在onCreate这个阶段获取不到数据(因为布局都没有创建出来)建议在其他生命周期状态中使用(建议在onResume())
注意事项
1
本步骤需要一定代码基础
2
程序代码以代码片段的形式展示
上一篇:Android的设计尺寸
下一篇:女人乳房最标准的10个形状