Android突破二之WindowManager、Display、DisplayMetrics类

来源:互联网 发布:网络维护的工作内容 编辑:程序博客网 时间:2024/05/01 12:46
                                                     
                                       WindowManager、Display、DisplayMetrics类
                                                                                                                                              Jiangdg_VIP
http://blog.csdn.net/u012637501
一、WindowManager类
1.概述应用程序使用这个接口与窗口管理器对话,并且每个窗口管理器对象都绑定在一个特定的Display类中。为获取一个WindowManager 窗口管理器并显示,可以使用 createDisplayContext(Display) 来为该显示获取一个Context ,然后使用  Context.getSystemService(Context.WINDOW_SERVICE)来获取窗口管理器。  
2.特征:公共接口继承于ViewManager
3.构造函数
4.重要方法解析
1. getDefaultDisplay()
    WindowManager实例创建新的窗口,然后返回一个Display对象。这个窗口管理器绑定在Display类对象中。
2.getWindowManager()
    用于获取窗口管理器,并返回WindowManager对象。
举例:获取窗口管理器
    WindowManager windowManager=getWindowManager();       //获取窗口管理器
    Display display=  windowManager.getDefaultDisplay();            //显示窗口并返回Display对象
 5.其他方法
abstract Display
getDefaultDisplay()
Returns the Display upon which this WindowManager instance will create new windows.
abstract void
removeViewImmediate(View view)
Special variation of removeView(View) that immediately invokes the given view hierarchy's View.onDetachedFromWindow() methods before returning.

二、Display类
(1)概述提供逻辑显示区域大小、密度的相关信息,应用程序显示区域指定的部分可能包含一个应用程序窗口的显示,排除系统装饰。应用程序显示区域可能比真正的显示区域要小,因为系统减去所需的空间装饰元素状态栏等。可以使用一下方法来获取应用程序显示区域的信息: getSize(Point), getRectSize(Rect) 和getMetrics(DisplayMetrics)
2.特征一个公共最终类,继承于java.lang.Object   ↳ android.view.Display
3.构造函数:无
4.重要方法解析
1.getMetrics(DisplayMetrics outMetrics)
作用:获取应用程序显示区域描述大小和密度的度量值。
2.void getSize(Point outSize)
作用:获取显示区域以像素为单位的宽和高。
5.其他方法
long
getAppVsyncOffsetNanos()
Gets the app VSYNC offset, in nanoseconds.
void
getCurrentSizeRange(Point outSmallestSize, Point outLargestSize)
Return the range of display sizes an application can expect to encounter under normal operation, as long as there is no physical change in screen size.
int
getDisplayId()
Gets the display id.
int
getFlags()
Returns a combination of flags that describe the capabilities of the display.
int
getHeight()
This method was deprecated in API level 13. Use getSize(Point) instead.
void
getMetrics(DisplayMetrics outMetrics)
Gets display metrics that describe the size and density of this display.
String
getName()
Gets the name of the display.
int
getOrientation()
This method was deprecated in API level 8. use getRotation()
int
getPixelFormat()
This method was deprecated in API level 17. This method is no longer supported. The result is always RGBA_8888.
long
getPresentationDeadlineNanos()
This is how far in advance a buffer must be queued for presentation at a given time.
void
getRealMetrics(DisplayMetrics outMetrics)
Gets display metrics based on the real size of this display.
void
getRealSize(Point outSize)
Gets the real size of the display without subtracting any window decor or applying any compatibility scale factors.
void
getRectSize(Rect outSize)
Gets the size of the display as a rectangle, in pixels.
float
getRefreshRate()
Gets the refresh rate of this display in frames per second.
int
getRotation()
Returns the rotation of the screen from its "natural" orientation.
void
getSize(Point outSize)
Gets the size of the display, in pixels.
int
getState()
Gets the state of the display, such as whether it is on or off.
float[]
getSupportedRefreshRates()
Get the supported refresh rates of this display in frames per second.
int
getWidth()
This method was deprecated in API level 13. Use getSize(Point) instead.
boolean
isValid()
Returns true if this display is still valid, false if the display has been removed.
String
toString()
Returns a string containing a concise, human-readable description of this object.

三、DisplayMetrics类
1.概述为一个描述显示区域信息的结构体类,比如大小、高度、密度、字体缩放等。为了访问DisplayMetrics成员,可以初始化一个对象如下所示:
 DisplayMetrics metrics = new DisplayMetrics();
 getWindowManager().getDefaultDisplay().getMetrics(metrics);
//即相当于:
 WindowManager windowManager=getWindowManager();       //获取窗口管理器
 Display display=  windowManager.getDefaultDisplay();            //显示窗口并返回Display对象
DisplayMetrics metrics = new DisplayMetrics();                        //通过DisplayMetrics多包含的信息,获取屏幕的宽和高
display.getMetrics(metrics);
2.特征:公共类
java.lang.Object
   ↳ android.util.DisplayMetrics
3.构造函数
    public DisplayMetrics()
4.方法
boolean
equals(Object o)
Compares this instance with the specified object and indicates if they are equal.
boolean
equals(DisplayMetrics other)
Returns true if these display metrics equal the other display metrics.
int
hashCode()
Returns an integer hash code for this object.
void
setTo(DisplayMetrics o)
void
setToDefaults()
String
toString()
Returns a string containing a concise, human-readable description of this object.
参考:http://developer.android.com/reference/android/util/DisplayMetrics.html


      

0 0
原创粉丝点击