android获得屏幕高度和宽度、状态栏高度

android获取屏幕的高度和宽度用到WindowManager这个类,两种方法:

WindowManager wm = (WindowManager) getContext()
                    .getSystemService(Context.WINDOW_SERVICE);

WindowManager wm = this.getWindowManager();

然后:

Point point=new Point();
wm.getDefaultDisplay().getSize(point);
int width = point.x;
int height = point.y;

获取状态栏高度

int result = 0;
int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) {
    result = context.getResources().getDimensionPixelSize(resourceId);
}

参考:android获得屏幕高度和宽度


你可能感兴趣的:(安卓学习)