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;