zoukankan      html  css  js  c++  java
  • Android获取屏幕的高度和宽度

      方法一:

    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中。

  • 相关阅读:
    Naive Operations HDU6315 (杭电多校2G)
    Baker Vai LightOJ
    LOJ#6278. 数列分块入门 2
    LOJ#6277. 数列分块入门 1
    Picture POJ
    Who Gets the Most Candies? POJ
    Dividing the Path POJ
    Balanced Sequence HDU
    归并排序
    Flying to the Mars
  • 原文地址:https://www.cnblogs.com/dazuihou/p/3647643.html
Copyright © 2011-2022 走看看