Skip to content

Android.view.WindowManager

Android Density 구하기

Get screen info...

DisplayMetrics metrics = new DisplayMetrics(); 
getWindowManager().getDefaultDisplay().getMetrics(metrics);
// 이 값은 0.75, 1.0, 1.5, 2.0 등의 값을 가지며
// 이 값에 dp을 곱하면 pixel 단위의 값을 구할 수 있습니다.
float dpi = metrics.density;

Android 화면크기 구하기

아래와 같은 방법으로 화면의 크기를 구할 수 있다. 단위는 픽셀이다. //(Gets the size of the display, in pixels.)//

int width = getWindowManager().getDefaultDisplay().getWidth();
int height = getWindowManager().getDefaultDisplay().getHeight();

Getting Height of Status and Title Bar

타이틀바와 상태바의 높이를 알아내는 방법은 아래와 같다.

Rect rect= new Rect();
// ((WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE)).
Window window = activity.getWindow();
window.getDecorView().getWindowVisibleDisplayFrame(rect);
int statusBarHeight = rect.top;
int contentViewTop = window.findViewById(Window.ID_ANDROID_CONTENT).getTop();
int titleBarHeight= contentViewTop - statusBarHeight;

See also

Favorite site