display getSize() 过时

来源:互联网 发布:js input隐藏 编辑:程序博客网 时间:2024/06/05 02:46
If you want the the display dimensions in pixels you can usegetSize: 
如果你想得到页面的像素值,使用getSize:

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


If you're not in an Activity you can get the default Display viaWINDOW_SERVICE: 
如果代码不在Activity中,你可以通过WINDOW_SERVICE得到屏幕尺寸:

WindowManager wm = (WindowManager)ctx.getSystemService(Context.WINDOW_SERVICE); 
Display display =wm.getDefaultDisplay(); 


Before getSize was introduced (in API level 13), you coulduse the getWidth and getHeight methods that are nowdeprecated: 
在getSize没有引入前(API level 13之前),你可以使用getWidth getHeight 。但是已经过时:

Display display =getWindowManager().getDefaultDisplay(); 
int width = display.getWidth();  //deprecated 
int height = display.getHeight();  //deprecated
0 0
原创粉丝点击