Android获取屏幕的高度和宽度
2024-08-25 17:12:09
方法一:
DisplayMetrics metrics=new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
int width=metrics.widthPixels;//屏幕的宽度
int height=metrics.heightPixels;//屏幕的高度
方法二:
Display display=getWindowManager.getDefaultDisplay();
Point point=new Point();
display.getSize(point);
int width=point.x;
int height=point.y;
getSize()方法的说明:
Note that this value should not be used for computing layouts, since a device will typically have screen decoration (such as a status bar) along the edges of the display that reduce the amount of application space available from the size returned here. Layouts should instead use the window size。
大体意思是这个方法不能用来计算布局大小,因为屏幕上的边缘的status bar等装饰减少了实际可获得的屏幕空间,而getSize方法是将减少后的屏幕大小的信息存入了Point中。
最新文章
- CSS系列:CSS中盒子之间的关系
- JavaScript - 基于CSS3动画的实现
- WinCE小结
- JVM实用参数(六) 吞吐量收集器
- 关于libsvm工具箱在64位matlab下的安装说明
- ROS vpn (pptp) 配置及端口绑定配置
- python网络爬虫(一):网络爬虫科普与URL含义
- c\c++复习基础要点08--c++单例模式
- arm mov 指令
- Hama学习总结
- AngularJS指南文档
- RocketMQ源码 — 八、 RocketMQ消息重试
- 测试 ASP.NET Core API Controller
- VueRouter和Vue生命周期(钩子函数)
- LeetCode(1): 两数之和
- TCP/UDP OSI_layer 4
- vue/cli 3.0 脚手架【进阶】 使用 amfe-flexible 和 postcss-px2rem进行移动端适
- ELK Stack (2) —— ELK + Redis收集Nginx日志
- Bootstrap下拉单学习
- GPIO口的输入输出模式
热门文章
- [LeetCode#55, 45]Jump Game, Jump Game II
- 数学概念——I - 数论,线性方程
- [Locked] Alien Dictionary
- lightoj 1300 边双联通分量+交叉染色求奇圈
- poj1016
- 414. Third Maximum Number
- sql给整数补零
- Vs 2008 对 OpenMP 的 支持 以及 OpenMP的环境变量及库函数
- 30余套系统模版|DIV+CSS网页模板|简洁大气系统模板
- __block的作用