方法一:

public static int SCREEN_WIDTH;

public static int SCREEN_HEIGHT;

//获取屏幕

WindowManager wm = (WindowManager) getBaseContext().getSystemService(

Context.WINDOW_SERVICE);

Display display = wm.getDefaultDisplay();

Point size = new Point();

display.getSize(size);

SCREEN_WIDTH= size.x;

SCREEN_HEIGHT= size.y;

display中getSize(Point)方法使用:

Display display = getWindowManager().getDefaultDisplay();

int width = display.getWidth(); // deprecated

int height = display.getHeight(); // deprecated

查看API 发现:

int getWidth()、int getHeight()方法:(我用的是level 19)

This method was deprecated in API level 13. Use

在看一下getSize(Point)方法:

public void getSize (Point outSize)

Gets the size of the display, in pixels.

Note that this value should not be used for computing layouts, since a device will typically have screen decoration (such as a status bar) along the edges of the display that reduce the amount of application space available from the size returned here. Layouts should instead use the window size.

The size is adjusted based on the current rotation of the display.

The size returned by this method does not necessarily represent the actual raw size (native resolution) of the display. The returned size may be adjusted to exclude certain system decoration elements that are always visible. It may also be scaled to provide compatibility with older applications that were originally designed for smaller displays

Parameters

outSize

A

那么到底怎么使用呢:

方案1:If you want the the display dimensions in pixels you can usegetSize:

Display display = getWindowManager().getDefaultDisplay();

Point size = new Point();

display.getSize(size);

int width = size.x;

int height = size.y;

方案2: if you're not in an Activity you can get the default Display viaWINDOW_SERVICE:

display = ((WindowManager)context.getSystemService(context.WINDOW_SERVICE)).getDefaultDisplay();

diswidth = getContext().getResources().getDisplayMetrics().widthPixels;

disheight = getContext().getResources().getDisplayMetrics().heightPixels;

android 中测量高度和宽度,android获得屏幕高度和宽度(display中getSize(Point)方法使用)...相关推荐

  1. 获取当前可视屏幕高度

    em 它是描述相对于应用在当前元素的字体尺寸,所以它也是相对长度单位.一般浏览器字体大小默认为16px,则2em == 32px: ex 依赖于英文字母小 x 的高度 ch 数字 0 的宽度 rem ...

  2. 怎么获取网页高度、屏幕高度、滚动高度?

    有时候需要取页面的底部, 就会用到document.body.clientHeight , 在HTML 标准中(这一句就能取到整个页面的高度, 不论body 的实际内容到底有多高. 在XHTML中, ...

  3. 如何获取网页高度、屏幕高度、滚动高度?

    有时候需要取页面的底部,就会用到 document.body.clientHeight,在HTML标准中这一句就能取到整个页面的高度,不论 body 的实际内容到底有多高. 在XHTML中,如果bod ...

  4. 获取页面、屏幕、div宽度

    使用原生方法 1 document.getElementById("d1").style.width; 这种只能获取到行内内联样式,也就是 1 <div id="d ...

  5. js获取文本高度和屏幕高度

    网页可见区域宽: document.body.clientWidth  网页可见区域高: document.body.clientHeight  网页可见区域宽: document.body.offs ...

  6. js 获取td高度_JS或jQuery获取宽高度

    javascript //网页可见区域宽: document.body.clientWidth //网页可见区域高: document.body.clientHeight //网页可见区域宽: doc ...

  7. Android中测量控件的宽和高

    前言:在Android开发中,有时候我们需要测量控件的宽和高,而直接调用getHeight(),getWidth(),getMeasureHeight(),getMeasureWidth()方法, 得 ...

  8. Android中获取软键盘状态和软键盘高度

    应用场景 在Android应用中有时会需要获取软键盘的状态(即软键盘是显示还是隐藏)和软键盘的高度.这里列举了一些可能的应用场景. 场景一 当软键盘显示时,按下返回键应当是收起软键盘,而不是回退到上一 ...

  9. Android中当item数量超过一定大小RecyclerView高度固定

    Android中当item数量超过一定大小时,将RecyclerView高度固定 方法1 直接通过LayoutParams来设定相应高度 ViewGroup.LayoutParams lp = rv. ...

最新文章

  1. 线程中CreateEvent和SetEvent及WaitForSingleObject的用法
  2. Swift实现Touch ID验证
  3. cronolog apache 日志分割
  4. SpringMVC:JSON
  5. python成长之路11
  6. 调整显示屏幕偏移和刷新频率[zt]
  7. Python教程:Python如何实现穷举搜索?
  8. 前端模块规范AMD/UMD/CommonJs
  9. java foreach跳出本次循环_Java中提供三种常用的循环语句
  10. 事件循环机制 + ES7:Async/Await(基于generator原理实现)附详细示例分析
  11. MySQL字段类型解析
  12. LittlevGL 开源图形库
  13. qq批量提取群成员_学会这个QQ营销技巧,助你一天引流200+
  14. 树莓派ssh远程登录连接默认账号密码
  15. 关于信息安全专业学习的一些看法
  16. 词霸天下---177 词根 【 -vast- = -wast- 空,荒废 】仅供学习使用
  17. Android 自定义apk名称
  18. 《国度》之大学者联盟全解
  19. latex附录中放python代码_LaTeX之附录设置
  20. 理解实时操作系统与裸机的区别

热门文章

  1. Linux设置界面或命令行启动
  2. Ext2.0框架的Grid使用介绍(转)
  3. 解决SpringMvc后台接收json数据中文乱码问题
  4. Javascript中的异步
  5. UI自动化新思路-基于RUNTIME的自动化测试设想
  6. Android启动脚本init.rc(2)
  7. 预定义变量 - PHP手册笔记
  8. 使用PHP对数据库输入进行恶意代码清除
  9. oracle 实现基于函数的索引
  10. Unity iOS打开AppStore评星页面,浅谈Application.OpenURL()方法。