zhihuitang
8/9/2015 - 3:32 PM

gistfile1.txt

/**
     * 获取手机分辨率
     */
    public static String getDisplayMetrix(Context context)
    {
        if (Constant.Screen.SCREEN_WIDTH == 0 || Constant.Screen.SCREEN_HEIGHT == 0)
        {
            if (context != null)
            {
                int width = 0;
                int height = 0;
                SharedPreferences DiaplayMetrixInfo = context.getSharedPreferences("display_metrix_info", 0);
                if (context instanceof Activity)
                {
                    WindowManager windowManager = ((Activity)context).getWindowManager();
                    Display display = windowManager.getDefaultDisplay();
                    DisplayMetrics dm = new DisplayMetrics();
                    display.getMetrics(dm);
                    width = dm.widthPixels;
                    height = dm.heightPixels;
 
                    Editor editor = DiaplayMetrixInfo.edit();
                    editor.putInt("width", width);
                    editor.putInt("height", height);
                    editor.commit();
                }
                else
                {
                    width = DiaplayMetrixInfo.getInt("width", 0);
                    height = DiaplayMetrixInfo.getInt("height", 0);
                }
 
                Constant.Screen.SCREEN_WIDTH = width;
                Constant.Screen.SCREEN_HEIGHT = height;
            }
        }
        return Constant.Screen.SCREEN_WIDTH + "×" + Constant.Screen.SCREEN_HEIGHT;
    }