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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • pycharm2022 2.3激活_在线激活2022.01.20

    (pycharm2022 2.3激活)最近有小伙伴私信我,问我这边有没有免费的intellijIdea的激活码,然后我将全栈君台教程分享给他了。激活成功之后他一直表示感谢,哈哈~IntelliJ2021最新激活注册码,破解教程可免费永久激活,亲测有效,下面是详细链接哦~https://javaforall.net/100143.html0H…

    2022年3月31日
    50
  • mqtt支持加密通讯

    mqtt支持加密通讯1.mqtt第三方库支持openssla,编译openssl库(我使用的是1.0.1),在mqtt源码目录下创建openssl文件夹,并拷贝编译完成的库文件与头文件到此文件夹下。b,修改mqtt(源码从git上获取https://github.com/eclipse/paho.mqtt.c.git)编译选项,PAHO_WITH_SSL,OPENSSL_SEARCH_PATH…

    2022年6月6日
    64
  • matlab 画图的颜色

    matlab 画图的颜色plot函数代表不同颜色的标示符一共有八种:y:黄色;k:黑色;w:白色;b:蓝色;g:绿色;r:红色;c:亮青色;m:锰紫色;其他的就要自己设定了,‘color’,[000];三原色你值得拥有;…

    2022年5月31日
    407
  • Petalinux2019.1详细安装[通俗易懂]

    Petalinux2019.1详细安装[通俗易懂]1、首先安装虚拟机,VMware2、安装UBUNTU,ubuntu-18.04.1-desktop-amd64.iso,版本必须是这个,和petalinux-v2019.1-final-installer.run版本对应。3、安装虚拟机完成后,在windos和linux之间建立共享文件夹,使之传输文件更简单。(1)首先取得管理员权限首先输入用户密码然后设置管理员密码123456su…

    2025年10月28日
    3
  • AnyCast技术浅析

    AnyCast技术浅析一常见通信方式1.1UniCastAnyCast1.2MultiCast1.3BroadCast二什么是BGPAnyCast三AnyCast技术特点四AnyCast应用场景4.1场景一:基于IPAnycast+BGP的DNS部署4.2场景二:防范DDOS攻击4.3场景三:大型企业CDN部署4.4场景四:时延敏感度高的内容服务业务五AnyCast总结5.1优点5.2缺点一常见通信方式1.1Un…

    2022年5月24日
    56
  • pycharm 解决控制台中文乱码[通俗易懂]

    pycharm 解决控制台中文乱码[通俗易懂]改为GBK即可

    2022年8月27日
    8

发表回复

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

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