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

上一篇:Struts2-----面试题汇总


下一篇:Jmeter教程 简单的压力测试