android 获取屏幕分辨率_安卓系统分辨率设置

android 获取屏幕分辨率_安卓系统分辨率设置在Activity中  //ME722测试480*854  竖屏Displaydisplay=this.getWindowManager().getDefaultDisplay();intnHeight=display.getHeight();     //569intnWidth=display.getWidth();       //320Displa

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

在Activity中

 

 // ME722 测试 480*854   竖屏

Display display = this.getWindowManager().getDefaultDisplay();
int nHeight = display.getHeight();      //569
int nWidth = display.getWidth();        //320
DisplayMetrics metrics = new DisplayMetrics();
display.getMetrics( metrics );
int nDeviceHeight = (int)(metrics.heightPixels * metrics.density);  // 569 * 1.5 = 853.5
int nDeviceWidth = (int)(metrics.widthPixels * metrics.density);    //  320 * 1.5 = 480

float fPhisycalHeight = metrics.heightPixels * metrics.density / metrics.densityDpi; // 3.55625
float fPhisycalWidth = metrics.widthPixels * metrics.density / metrics.densityDpi; // 2.0

 

在AndroidManifest.xml中添加 <supports-screens android:anyDensity=”true”/>  之后

或者是添加<uses-sdk android:minSdkVersion=”4″ /> 之后(最小版本号是4以及以上)

 

Display display = this.getWindowManager().getDefaultDisplay();
int nHeight = display.getHeight();      //854

int nWidth = display.getWidth();        //480

display.getMetrics( metrics );
metrics.heightPixels   854 
metrics.widthPixels 480

metrics.density 1.5

 

多看Dev Guide 

 

 Lets you specify the screen dimensions the application supports. By default, a modern application (using API Level 4 or higher) supports all screen sizes; older applications are assumed to support only the “normal” screen size. Screen size is determined as the available pixels to an application after density scaling has been applied. (Note that screen size is a separate axis from screen density.)

Constants

public static final int DENSITY_DEFAULT

Since:
 
API Level 4

The reference density used throughout the system.

Constant Value:  160 (0x000000a0)

public static final int DENSITY_HIGH

Since:
 
API Level 4

Standard quantized DPI for high-density screens.

Constant Value:  240 (0x000000f0)

public static final int DENSITY_LOW

Since:
 
API Level 4

Standard quantized DPI for low-density screens.

Constant Value:  120 (0x00000078)

public static final int DENSITY_MEDIUM

Since:
 
API Level 4

Standard quantized DPI for medium-density screens.

Constant Value:  160 (0x000000a0)

public static final int DENSITY_XHIGH

Since:
 
API Level 9

Standard quantized DPI for extra-high-density screens.

Constant Value:  320 (0x00000140)

An application “supports” a given screen size if it fills the entire screen and works as expected. By default, the system will resize your application to fill the screen, if you have set either minSdkVersion or targetSdkVersion to "4" or higher. Resizing works well for most applications and you don’t have to do any extra work to make your application work on larger screens.

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/170370.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 最新 Linux 命令总结 大全[通俗易懂]

    今天,带来一篇Linux命令总结的非常全的文章,也是我们平时工作中使用率非常高的操作命令,命令有点多,建议小伙伴们可以先收藏后阅读。目录1.基本命令2.关机3.文件和目录4.文件搜索5.挂载一个文件系统6.磁盘空间7.用户和群组8.文件的权限使用“+”设置权限,使用“-”用于取消9.文件的特殊属性,使用“+”设置权限,使用“-”用于取消10.打包和压缩文件11.RPM包12.YUM软件包升级器13.deb包14.查看文件内容15.文本处理16

    2022年4月10日
    63
  • 数据库表设计之用户权限表[通俗易懂]

    数据库表设计之用户权限表[通俗易懂]需求分析1、管理员给用户分配权限,权限数据写到数据库中。2、认证服务在进行用户认证时从数据库读取用户的权限数据(动态数据)user:用户表,存储了系统用户信息,用户类型包括:学生、老师、管理员等role:角色表,存储了系统的角色信息,学生、老师、教学管理员、系统管理员等user_role:用户角色表,一个用户可拥有多个角色,一个角色可被多个用户所拥有menu:记录了菜单及菜单下的权限role_permission:角色权限表,一个角色可拥有多个权限,一个权限可被多个角色所拥有…

    2022年9月29日
    2
  • 计算机网络基本知识汇总「建议收藏」

    计算机网络基本知识汇总「建议收藏」概述OSI分层(7层)物理层、数据链路层、网络层、运输层、会话层、表示层、应用层TCP/IP分层(4层)网络接口层、网络层、运输层、应用层五层协议(5层)物理层、数据链路层、网络层、运输层、应用层五层结构的概述应用层:通过应用进程间的交互来完成特定网络应用数据:报文协议:HTTP,SMTP(邮件),FTP(文件传送)运输层:向两个主机进程之间的通信提供通用的数据传输服务。

    2022年7月18日
    19
  • java打印菱形思路[通俗易懂]

    java打印菱形思路[通俗易懂]总共2个大的for循环  里边有小的对吧第一个大的for是打印菱形的上半部分for(i=1;i  { 这个小的for是打印每一行前边的空格   for(j=1;j   System.out.print(“”); 这个是打印星星的   for(j=1;j   System.out.print(“*”); 这个是打印完一行的换行  S

    2022年9月29日
    3
  • 安装pyodbc_编程python是什么

    安装pyodbc_编程python是什么1、连接数据库pipinstallpyodbc成功后就可以用了首先要importpyodbc1)直接连接数据库和创建一个游标(cursor)cnxn=pyodbc.connect(‘DRIVER={SQLServer};SERVER=localhost;DATABASE=testdb;UID=me;PWD=pass’)cursor=cnxn.cursor()2)使用DSN连接。通常DSN连接并不需要密码,还是需要提供一个PSW的关键字。cnxn=pyodb

    2022年4月19日
    61
  • Excel 宏编程的常用代码

    Excel 宏编程的常用代码Excel宏编程的常用代码我们常用Excel统计一些数据,如果善用VBA,就能自动做出各种复杂的报表,懒人就是追求一劳永逸!不过,也不是真懒啦,只是用智慧(脑力劳动)将自身从体力劳动中解放出来而已,人类也是这样进步的。我有这样的感觉,就是每见到一个语句或函数,都会激发出偷懒的灵感来,哈哈,很自恋了,其实好玩而已。————————-

    2022年6月11日
    111

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号