Android 屏幕宽度、高度

public class WindowManagerUtils {

    public int getScreenHigh(Context context,String xyType){
        WindowManager windowManager = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
        Display display = windowManager.getDefaultDisplay();
        Point outPoint = new Point();
        if (Build.VERSION.SDK_INT >= 19) {
            // 可能有虚拟按键的情况
            display.getRealSize(outPoint);
        } else {
            // 不可能有虚拟按键
            display.getSize(outPoint);
        }
        int mRealSizeWidth;//手机屏幕真实宽度
        int mRealSizeHeight;//手机屏幕真实高度
        mRealSizeHeight = outPoint.y;
        mRealSizeWidth = outPoint.x;
        if (xyType.equals("x")){
            return mRealSizeWidth;
        }else if (xyType.equals("y")){
            return mRealSizeHeight;
        }
        return 0;
    }
}

 

你可能感兴趣的:(Android 屏幕宽度、高度)