方法一:

DisplayMetrics metrics=new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
int width=metrics.widthPixels;//屏幕的宽度
int height=metrics.heightPixels;//屏幕的高度

  方法二:

Display display=getWindowManager.getDefaultDisplay();
Point point=new Point();
display.getSize(point);
int width=point.x;
int height=point.y;

  getSize()方法的说明:

  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。

  大体意思是这个方法不能用来计算布局大小,因为屏幕上的边缘的status bar等装饰减少了实际可获得的屏幕空间,而getSize方法是将减少后的屏幕大小的信息存入了Point中。

Android获取屏幕的高度和宽度的更多相关文章

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

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

  2. Android进阶笔记18:Android 获取Button的高度、宽度、坐标值

    1. 问题 如何获取一个控件的长和高,相信很多朋友第一眼看见这个问题都会觉得很简单,直接在onCreate里面调用getWidth.getMeasuredWidth不就可以获得了吗,但是,事实上是并没 ...

  3. Android获取屏幕实际高度跟显示高度,判断Android设备是否拥有虚拟功能键

    //获取屏幕尺寸,不包括虚拟功能高度 getWindowManager().getDefaultDisplay().getHeight(); 获取屏幕原始尺寸高度,包括虚拟功能键高度, private ...

  4. 用JS 和 jQery获取屏幕的高度和宽度

    用的时候,网上找了下,放在一起,方便以后查阅 document.body.clientWidth document.body.offsetWidth(包括线宽)//网页可见区域宽 document.b ...

  5. Android取得屏幕的高度和宽度

    //获得手机屏幕的宽度和高度 width=getWindowManager().getDefaultDisplay().getWidth(); height=getWindowManager().ge ...

  6. Android获取屏幕宽和高

    android获取屏幕的高度和宽度用到WindowManager这个类,两种方法:   1.WindowManager wm = (WindowManager) getContext()        ...

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

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

  8. JavaScript获取屏幕和页面的宽度和高度

    JavaScript获取屏幕和页面的宽度和高度 1.设计源码 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN ...

  9. Android 在OnCreate()中获取控件高度与宽度

    试过在OnCreate()中获取控件高度与宽度的童鞋都知道,getWidth()与getHeight()方法返回是0,具体原因 看一下Activity的生命周期 就会明白. 上代码: 方法一: int ...

随机推荐

  1. 数据结构(线段树):CodeForces 145E Lucky Queries

    E. Lucky Queries time limit per test 3 seconds memory limit per test 256 megabytes input standard in ...

  2. VS2010中的自动化测试(5)——Web性能测试

    原文地址:http://www.cnblogs.com/heqichang/archive/2011/11/20/2256478.html 类目见这里:http://www.cnblogs.com/h ...

  3. UVa11613 Acme Corporation(最小费用流)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=33452 [思路] 最小费用流. 构图: 1 每个月建立2个点,建立 ...

  4. First Record

    今天我在博客园安家了! R Python Scala hadoop Spark MachineLearning

  5. [Locked] Read N Characters Given Read4 & Read N Characters Given Read4 II - Call multiple times

    Read N Characters Given Read4 The API: int read4(char *buf) reads 4 characters at a time from a file ...

  6. SRM 507(2-1000pt)

    DIV2 1000pt 题意:在一个长度无限的数轴上移动一个方块,每次可以向左或者向右移动距离x,只要x为完全平方数.数轴上有一些坑,如果方块移动到坑上则方块会掉进坑中,不能再被移动.给整数s,e,和 ...

  7. 什么是method swizzling

    其实跟字面的意思很相近.方法的调和.可以去修改oc中两个方法的调用. 这张图看起来会比较形象 20130718230430859.png 就是把两个实现调换具体的做法,首先,用Categroy建立自己 ...

  8. 使用drawRect有什么影响

    用来画图,这个方法会在intiWithRect时候调用.这个方法的影响在于有touch event的时候之后,会重新绘制,很多这样的按钮的话就会比较影响效率.以下都会被调用1.如果在UIView初始化 ...

  9. viewWillLayoutSubView

    当viewController的bounds又改变,调用这个方法来实现subview的位置.可重写这个方法来实现父视图变化subview跟着变化.                   > Lif ...

  10. Sublime 注册码

    ----- BEGIN LICENSE ----- Andrew Weber Single User License EA7E-855605 813A03DD 5E4AD9E6 6C0EEB94 BC ...