只要调用方法即可
1. 获取手机屏幕宽高
private int mScreenWidth;//屏宽
private int mScreenHeight;//屏高
private void getScreenSize() {
Display display = getWindowManager().getDefaultDisplay(); //Activity#getWindowManager()
Point size = new Point();
display.getSize(size);
mScreenWidth = size.x;
mScreenHeight = size.y;
}
2.获取屏幕状态栏宽高(一般高都是25)
private int statusBarHeight;//状态栏高
private void getScreenStatusHeight(){
Class<?> c = null;
Object obj = null;
Field field = null;
int x = 0, sbar = 0;
try {
c = Class.forName("com.android.internal.R$dimen");
obj = c.newInstance();
field = c.getField("status_bar_height");
x = Integer.parseInt(field.get(obj).toString());
sbar = getResources().getDimensionPixelSize(x);
} catch (Exception e1) {
e1.printStackTrace();
}
statusBarHeight = DensityUtil.px2dip(this,sbar);
Log.i("common","高statusBarHeight-->"+statusBarHeight);
}