在实际的项目中,我们经常要得到当前屏幕的分辨率,进行机型适配,得到分辨率其实很简单,主要有两种方法。

方法一:

Display mDisplay = getWindowManager().getDefaultDisplay();
int W = mDisplay.getWidth();
int H = mDisplay.getHeight();
Log.i("Main", "Width = " + W);
Log.i("Main", "Height = " + H);

Display是在android.view.Display包中的。

方法二:

DisplayMetrics mDisplayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(mDisplayMetrics);
int W = mDisplayMetrics.widthPixels;
int H = mDisplayMetrics.heightPixels;
Log.i("Main", "Width = " + W);
Log.i("Main", "Height = " + H);

DisplayMetrics是在android.util.DisplayMetrics包中的,getWindowManager()是Activity中的方法。

最新文章

  1. Quartus II USB-Blaster驱动解决
  2. Altium Designer 15 --- Make 3D PCB Library with Rhinoceros
  3. springmvc学习笔记---面向移动端支持REST API
  4. error: property's synthesized getter follows Cocoa naming convention for returning 'owned' objects
  5. AngularJS之Service4
  6. Delphi基本图像处理方法汇总
  7. trident-deploy自动部署命令
  8. springboot与Mybatis结合
  9. 自学python之路(day3)
  10. Debian9 使用 Docker 安装 gitlab完整过程
  11. 利用DWORD SHOOT实现堆溢出的利用(先知收录)
  12. 20181223 python 使用Beautiful Soup
  13. Centos6.8 smokeping安装
  14. Vim正则表达式匹配替换字符串
  15. SQL Server通过外部程序集注册正则表达式函数(CLR函数) [转]
  16. Ora-01536:超出了表空间users的空间限量
  17. 远程登录 dos命令
  18. CUDA C Programming Guide 在线教程学习笔记 Part 3
  19. React Native新手入门
  20. Objective-C:动态绑定

热门文章

  1. 创建Fragment和传递数值
  2. AndroidStudio 添加Selector文件,在res文件夹下添加文件夹
  3. Spring Cloud与Spring Boot的关系
  4. Python3【模块】concurrent.futures模块,线程池进程池
  5. 宿主机mount虚拟机镜像文件
  6. 限制printk打印频率函数printk_ratelimit【转】
  7. Linux 入门记录:四、Linux 系统常用命令
  8. C++ Primer读书笔记
  9. SQL中char、nchar、varchar、nvarchar、text概述【转】
  10. LeetCode214. Shortest Palindrome