Android屏幕区域划分及尺寸获取
16lz
2021-01-25
Android屏幕可以划分为五个区域
1. 整个屏幕
获取方法为getRealSize或getRealMetrics,或直接从根窗口DecorView中获取 1)方法1 Point outSize = new Point();getWindowManager().getDefaultDisplay().getRealSize(outSize);int x = outSize.x;int y = outSize.y; 2)方法2DisplayMetrics outMetrics = new DisplayMetrics();getWindowManager().getDefaultDisplay().getRealMetrics(outMetrics);int widthPixel = outMetrics.widthPixels;int heightPixel = outMetrics.heightPixels; 3)方法3 DecorView view=getWindow().getDecorView(); int width = view.getWidth(); //getWidth方法可能是过时了,不过不要紧,你输入的时候IDE会提示修改 int height = view.getHeight(); //getHeight方法可能是过时了,不过不要紧,你输入的时候IDE会提示修改
2. 应用程序区
获取方法为getSize或getMetrics,即上述屏幕方法中去掉Real,或直接从根窗口DecorView中获取1)方法1Display defaultDisplay = getWindowManager().getDefaultDisplay(); Point point = new Point(); defaultDisplay.getSize(point); int x = point.x; int y = point.y; 2)方法2 Rect outSize = new Rect(); getWindowManager().getDefaultDisplay().getRectSize(outSize); int left = outSize.left; int top = outSize.top; int right = outSize.right; int bottom = outSize.bottom; 3)方法3 DisplayMetrics outMetrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(outMetrics); int widthPixels = outMetrics.widthPixels; int heightPixels = outMetrics.heightPixels;4)方法4Rect outRect = new Rect(); View view = getWindow().getDecorView(); view.getWindowVisibleDisplayFrame(outRect); int width = outRect.width(); int height = outRect.height();
3. 应用程序区内容区
View view2 = getWindow().findViewById(Window.ID_ANDROID_CONTENT); int width = view2.getWidth(); int height = view2.getHeight();
4. 标题栏及状态栏
用以上获取的各区域相减即可得出
更多相关文章
- Android(安卓)Activity切换动画overridePendingTransition
- Android中使用Fragment实现标题栏(不可滑动)
- Android(安卓)-- 跨应用绑定service并通信
- [Android开发]Android(安卓)重要组件 之 Intent
- 【Android(安卓)开发教程】重新布局
- lua学习笔记 2 android调用Lua。Lua脚本中实现添加Button,并为Bu
- Android(安卓)容器控件
- Mac Android(安卓)Studio处理unable to access android sdk add-
- Android(安卓)onCreate方法被调用两次的解决方法