方法一:

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中。

最新文章

  1. CSS系列:CSS中盒子之间的关系
  2. JavaScript - 基于CSS3动画的实现
  3. WinCE小结
  4. JVM实用参数(六) 吞吐量收集器
  5. 关于libsvm工具箱在64位matlab下的安装说明
  6. ROS vpn (pptp) 配置及端口绑定配置
  7. python网络爬虫(一):网络爬虫科普与URL含义
  8. c\c++复习基础要点08--c++单例模式
  9. arm mov 指令
  10. Hama学习总结
  11. AngularJS指南文档
  12. RocketMQ源码 — 八、 RocketMQ消息重试
  13. 测试 ASP.NET Core API Controller
  14. VueRouter和Vue生命周期(钩子函数)
  15. LeetCode(1): 两数之和
  16. TCP/UDP OSI_layer 4
  17. vue/cli 3.0 脚手架【进阶】 使用 amfe-flexible 和 postcss-px2rem进行移动端适
  18. ELK Stack (2) —— ELK + Redis收集Nginx日志
  19. Bootstrap下拉单学习
  20. GPIO口的输入输出模式

热门文章

  1. [LeetCode#55, 45]Jump Game, Jump Game II
  2. 数学概念——I - 数论,线性方程
  3. [Locked] Alien Dictionary
  4. lightoj 1300 边双联通分量+交叉染色求奇圈
  5. poj1016
  6. 414. Third Maximum Number
  7. sql给整数补零
  8. Vs 2008 对 OpenMP 的 支持 以及 OpenMP的环境变量及库函数
  9. 30余套系统模版|DIV+CSS网页模板|简洁大气系统模板
  10. __block的作用