方法一:

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) instead. 

在看一下getSize(Point)方法:

public void getSize (Point outSize)

Added in API level 13

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 Point object to receive the size information. 
那么到底怎么使用呢:
方案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获得屏幕高度和宽度(display中getSize(Point)方法使用)的更多相关文章

  1. android获得屏幕高度和宽度

    获取屏幕的宽度与高度有以下几种方法: .WindowManager wm = (WindowManager) getContext()                     .getSystemSe ...

  2. 【笔记】css 实现宽度自适应屏幕 高度自适应宽度

    如果说宽高自适应屏幕尺寸那么大家可能会想到 div{ width: 100%; height: 100% } 但是如果我要自适应屏幕尺寸的同时还要变成正方形呢?(高度和宽度相等而高度不能写死) 那就要 ...

  3. JavaScript浏览器对象(BOM)中有关设备、浏览器屏幕高度和宽度的API介绍

    JavaScript世界中,有很多看起来能够帮我们知道网页宽度和高度的API,但太繁多了,而且容易弄混.不容易区分它们.下面我就来介绍一下,这些API到底是什么意思,之间的区别又在哪里. 一.设备的分 ...

  4. css设置div高度与宽度相等的一种方法

    div.category{ width:33%; padding:33% 0 0; } 1.关键在padding:33% 0 0这句代码,通过设置padding-top与宽度相等(padding使用百 ...

  5. 网页或微信小程序中使元素占满整个屏幕高度

    在项目中经常要用到一个容器元素占满屏幕高度和宽度,然后再在这个容器元素里放置其他元素. 宽度很简单就是width:100% 但是高度呢,我们知道的是height:100%必须是在父元素的高度给定了的情 ...

  6. Android 关于屏幕适配

    android屏幕适配详解 官方地址:http://developer.android.com/guide/practices/screens_support.html 转自:http://www.c ...

  7. 获取Android状态栏的高度

    Android 开发中经常需要知道屏幕高度.宽度.状态栏,标题栏的高度等 宽度和高度 WindowManager windowManager = (WindowManager) getSystemSe ...

  8. android 获取屏幕的高度和宽度、获取控件在屏幕中的位置、获取屏幕中控件的高度和宽度

    (一)获取屏幕的高度和宽度 有两种方法: 方法1: WindowManager wm = (WindowManager) getContext().getSystemService(Context.W ...

  9. Android 修改toast的默认位置和获取当前屏幕的高度和宽度

    Toast toast; toast=Toast.makeText(this, "toast", Toast.LENGTH_LONG); toast.setGravity(grav ...

随机推荐

  1. 增删查改-MySQL

    查询: 在MySQL中,select的基本语法形式: select 属性列表 from 表名和视图 [where 条件表达式] [group by 属性名 [having 条件表达式]] [order ...

  2. jquery 实现飘落效果

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  3. C#:.net/方法/字符串/数组

    C#:.net/方法/字符串/数组,那点事 首先还是先说下(几个概念的东西)c#下的.net平台的构造快及其功能作用和程序集: .net: .net平台是由:a:运行库+b:全面基础类库(这个是从程序 ...

  4. SuperMap iClient

    SuperMap iClient 7C——网络客户端GIS开发平台 产品新特性   SuperMap iClient 7C是空间信息和服务的可视化交互开发平台,是SuperMap服务器系列产品的统一客 ...

  5. iphone手机用wireshark抓包

    ios连上电脑 查看udid. 启动虚拟接口 rvictl -s 7e65eeaa55a1e43dbdfb44a02f9871f1f304043e 打开mac权限 sudo chmod 644 /de ...

  6. 有一个array的数组,长度为10000,大小不一,用算法找出该数组中的最大值。

    不用算法的答案是:   var a=[1,2,3,5……];alert(Math.max.apply(null, a));//最大值alert(Math.min.apply(null, a));//最 ...

  7. OpenCascade

    Hello World of OpenCascade   Hello World of OpenCascade eryar@163.com 摘要Abstract:以一个经典的Hello World程序 ...

  8. java读取properties 文件信息

      src下config/tank.properties文件 initTankCount=10 ReinitTankCount=8 Etmspeed=15 Mtmspeed=15 MTankCount ...

  9. Windows下的环境搭建Erlang

    Windows下的环境搭建 Erlang 一.安装编译器 在http://www.erlang.org/download.html下载R16B01 Windows Binary File并安装. 二. ...

  10. 做了一个quartz用到的cron在线生成器

    做了一个quartz用到的cron在线生成器 做了一个quartz用到的cron在线生成器   做这个的目的是前期在做Quartz时老是不知道如何去写,我想也有很多人和我一样吧. 有一次使用了一个老外 ...