DisplayでgetHeight()とgetWidth()の公式廃棄

1876 ワード

今日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.