Android如何获取屏幕的分辨
2024-08-28 09:49:29
在实际的项目中,我们经常要得到当前屏幕的分辨率,进行机型适配,得到分辨率其实很简单,主要有两种方法。
方法一:
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中的方法。
最新文章
- Quartus II USB-Blaster驱动解决
- Altium Designer 15 --- Make 3D PCB Library with Rhinoceros
- springmvc学习笔记---面向移动端支持REST API
- error: property&;#39;s synthesized getter follows Cocoa naming convention for returning &;#39;owned&;#39; objects
- AngularJS之Service4
- Delphi基本图像处理方法汇总
- trident-deploy自动部署命令
- springboot与Mybatis结合
- 自学python之路(day3)
- Debian9 使用 Docker 安装 gitlab完整过程
- 利用DWORD SHOOT实现堆溢出的利用(先知收录)
- 20181223 python 使用Beautiful Soup
- Centos6.8 smokeping安装
- Vim正则表达式匹配替换字符串
- SQL Server通过外部程序集注册正则表达式函数(CLR函数) [转]
- Ora-01536:超出了表空间users的空间限量
- 远程登录 dos命令
- CUDA C Programming Guide 在线教程学习笔记 Part 3
- React Native新手入门
- Objective-C:动态绑定
热门文章
- 创建Fragment和传递数值
- AndroidStudio 添加Selector文件,在res文件夹下添加文件夹
- Spring Cloud与Spring Boot的关系
- Python3【模块】concurrent.futures模块,线程池进程池
- 宿主机mount虚拟机镜像文件
- 限制printk打印频率函数printk_ratelimit【转】
- Linux 入门记录:四、Linux 系统常用命令
- C++ Primer读书笔记
- SQL中char、nchar、varchar、nvarchar、text概述【转】
- LeetCode214. Shortest Palindrome