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


相关推荐

  • 达梦数据库备份还原使用

    达梦数据库备份还原使用达梦数据库备份还原使用一、关于备份二、物理备份三、逻辑备份一、关于备份1、备份的作用:①、防止误操作②、软硬件故障,做恢复③、防止天灾2、备份的方式:逻辑备份和物理备份3、备份的介质:磁盘,磁带,光盘支持第三方的备份软件:如上海爱数,鼎甲等。二、物理备份物理备份分为:冷备和热备冷备:DMAP服务是打开的,数据库实例是关闭的方式1:利用控制台工具去备2、DMRM…

    2022年5月14日
    53
  • jmeter相关面试题_jmeter面试题及答案

    jmeter相关面试题_jmeter面试题及答案一、接口测试1、接口测试流程1、首先是从开发那里拿到API接口文档,了解接口业务、包括接口地址、请求方式,入参、出参,token鉴权,返回格式等信息。2、然后使用Postman或Jmeter工具执行接口测试,一般使用Jmeter的步骤是这样的: a、首先新建一个线程组。 b、然后就是新建一个HTTP请求默认值。(输入接口服务器IP和端口) c、再新建很多HTTP请求,一个请求一个用例。(输入接口路径,访问方式,参数等) d、然后创建断言和查看结果树。3、最后调试并执行用例,最后编写接口测试报

    2022年9月30日
    3
  • Delphi 控件复制_delphi10教程

    Delphi 控件复制_delphi10教程下载:DevExpressVCL5.3

    2022年9月24日
    4
  • byte转string字符

    byte转string字符开发过程中从数据库拿出来的数据用tostring会显示为System.Byte[]查了下资料要发现网上的都不适用记录下自己的foreach(DataRowrowinds.Tables[0].Rows){    byte[]datbytes=(byte[])row["dat"];    for(inti=0;i&lt;datbytes.Length;i++)…

    2022年6月29日
    65
  • C语言 排序算法_C语言中三大经典的排序算法

    C语言 排序算法_C语言中三大经典的排序算法文章目录前言一、插入排序1.1直接插入排序1.2希尔排序二、使用步骤1.引入库2.读入数据总结前言常见的排序算法如下:一、插入排序1.1直接插入排序基本思想:把待排序的记录按其关键码值的大小逐个插入到一个已经排好序的有序序列中,直到所有的记录插入完为止,得到一个新的有序序列。实际中我们玩扑克牌时,就用了插入排序的思想:当插入第i(i>=1)个元素时,前面的array[0],array[1],…,array[i-1]已经排好序,此时用array[i]的排序码与array[i-1],a

    2025年6月19日
    2
  • UML图画法_画用例图的步骤

    UML图画法_画用例图的步骤一.用例图的作用用例图主要用来描述“用户、需求、系统功能单元”之间的关系。它展示了一个外部用户能够观察到的系统功能模型图。【用途】:帮助开发团队以一种可视化的方式理解系统的功能需求。二.用例图包含的元素 1.参与者(Actor)  表示与您的应用程序或系统进行交互的用户、组织或外部系统。用一个小…

    2022年9月7日
    2

发表回复

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

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