Display中getHeight()和getWidth() 官方廢棄


        今天使用Display獲取屏幕的寬和高時出現下面的提示:

Display dp=getWindowManager().getDefaultDisplay();
        int Height=dp.getHeight();  ---->The method getHeight() from the type Display is deprecated
        int Width=dp.getWidth();    ---->The method getWidth() from the type Display is deprecated
官方解釋:
int
getHeight() This method was deprecated in API level 13. Use getSize(Point) instead. int getWidth() This method was deprecated in API level 13. Use getSize(Point) instead. http://developer.android.com/reference/android/view/Display.html
替代的方法:
DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); SCREEN_WIDTH = dm.widthPixels; SCREEN_HEIGHT = dm.heightPixels;

解析heightPixels和widthPixels:
public int     heightPixels     The absolute height of the display in pixels.
public int     widthPixels     The absolute width of the display in pixels.

 

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM