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

  • 相关阅读:
    oracle重命名数据库
    GridView分页的实现
    vb发post信息,非常简单,就一个函数
    第六周进度条
    软件工程作业
    进度条第五周
    四则运算设计03
    进度条03
    单元测试课堂作业
    个人作业02
  • 原文地址:https://www.cnblogs.com/dazuihou/p/3647643.html
Copyright © 2011-2022 走看看