• 已删除用户
Administrator
发布于 2017-07-05 / 66 阅读
1

Android获取屏屏的物理大小,即尺寸

public double screenInches() {
    WindowManager wm = (WindowManager) 
    getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    // 屏幕宽度
    float screenWidth = display.getWidth();
    // 屏幕高度
    float screenHeight = display.getHeight();
    DisplayMetrics dm = new DisplayMetrics();
    display.getMetrics(dm);
    double x = Math.pow(dm.widthPixels / dm.xdpi, 2);
    double y = Math.pow(dm.heightPixels / dm.ydpi, 2);
    // 屏幕尺寸
    double screenInches = Math.sqrt(x + y);
    return screenInches ;
 }