03 DisplayMetrics

WindowManager-->Display-->DisplayMetrics


(1)

DisplayMetrics metrics = new DisplayMetrics();

getWindowManager().getDefaultDisplay().getMetrics(metrics);

(2)

DisplayMetrics metrics = new DisplayMetrics();
((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getMetrics(metrics);


DisplayMetrics:

public float density The logical density of the display.
public int densityDpi The screen density expressed as dots-per-inch.
public int heightPixels The absolute height of the display in pixels.
public float scaledDensity A scaling factor for fonts displayed on the display.
public int widthPixels The absolute width of the display in pixels.
public float xdpi The exact physical pixels per inch of the screen in the X dimension.
public float ydpi The exact physical pixels per inch of the screen in the Y dimension.

============================================================================

Rect rt = new Rect();
View.getWindowVisibleDisplayFrame(rt);


============================================================================

getContext().getResources().getDisplayMetrics().widthPixels;




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章