方法一:

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. Day3:T1数论+高精 T2搜索

    T1:数论+高精(水~) 根据题意可知,从除的数越大越好(在0~9中) 所以我们只要用到高精除然后再模拟一下就可以了 //MARK:但是要注意0-9这个特殊值需要特判,因为题目要求输出的数至少是两位数 ...

  2. iOS由ImageIO.framework实现gif的系统解码

    首先先简单介绍一下gif的几个算是术语吧: frame(帧):一个gif可以简单认为是多张image组成的动画,一帧就是其中一张图片image. frameCount(帧数): 就是一个gif有多少帧 ...

  3. 写一个简单的Web框架

    在.Net中有两种常用的Web开发方式,一种是Asp.Net WebForm,另一种是Asp.Net MVC.我先简单的给大家介绍下这两种开发方式的特点,然后再应用自定义脚本映射,反射,json2te ...

  4. phpredis扩展

    <?php $redis = new Redis(); $redis->connect('127.0.0.1',6379); $redis->set('test','hello wo ...

  5. [置顶] github 出现 Permission denied (publickey)的解决

    今天写了一篇博客,想push到github上的时候出现了以下错误 Permission denied (publickey). fatal: The remote end hung up unexpe ...

  6. UVa-Where's Waldorf?

    题目地址:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  7. 横瓜从WP7与WP8不兼容之处预测微软公司在未来20年将会倒闭

    横瓜(601069289)  12:40:50 微软频繁升级操作系统版本捞钱,还不向下兼容,其企业的核心竞争力不再是技术,是钱!除了操作系统,其它产品没有任何核心技术和竞争力,微软必死. 横瓜从WP7 ...

  8. eclipse调试java调用matlab程序的7.17dll找不到的问题

    经过多次查找,这个问题本来很简单,在环境变量中CLASSPATH配置C:\MATLAB\R2012a\toolbox\javabuilder\jar\win64\javabuilder.jar 特别注 ...

  9. 谈谈new Thread的弊端及Java四种线程池的使用

    1.new Thread的弊端执行一个异步任务你还只是如下new Thread吗? new Thread(new Runnable() { @Override public void run() { ...

  10. Linux中的task,process, thread 简介

    本文的主要目的是介绍在Linux内核中,task,process, thread这3个名字之间的区别和联系.并且和WINDOWS中的相应观念进行比较.如果你已经很清楚了,那么就不用往下看了. LINU ...