【问题标题】:How to get complete screen size of device programmatically in android?如何在android中以编程方式获取设备的完整屏幕尺寸?
【发布时间】:2013-11-26 11:09:56
【问题描述】:

我正在以编程方式为 Tablet nexus7" 计算设备的屏幕尺寸,它给出 6.7 。但 Nexus7" 的屏幕尺寸为 7"。 我想获得设备的完整屏幕尺寸。 这是我的代码:-

DisplayMetrics dm = new DisplayMetrics();
        getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
        double x = Math.pow(dm.widthPixels / dm.xdpi, 2);
        double y = Math.pow(dm.heightPixels / dm.ydpi, 2);
        screenInches = Math.sqrt(x + y);

【问题讨论】:

    标签: android screen-size


    【解决方案1】:

    尝试如下

    int screenSize = getResources().getConfiguration().screenLayout &
            Configuration.SCREENLAYOUT_SIZE_MASK;
    
    switch(screenSize) {
        case Configuration.SCREENLAYOUT_SIZE_LARGE:
            Toast.makeText(this, "Large screen",Toast.LENGTH_LONG).show();
            break;
        case Configuration.SCREENLAYOUT_SIZE_NORMAL:
            Toast.makeText(this, "Normal screen",Toast.LENGTH_LONG).show();
            break;
        case Configuration.SCREENLAYOUT_SIZE_SMALL:
            Toast.makeText(this, "Small screen",Toast.LENGTH_LONG).show();
            break;
        default:
            Toast.makeText(this, "Screen size is neither large, normal or small" , Toast.LENGTH_LONG).show();
    }
    

    【讨论】:

    • 我必须在我的应用程序中获取屏幕尺寸。
    • 我需要以英寸为单位的屏幕尺寸。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-17
    • 2013-01-06
    • 1970-01-01
    • 2013-07-03
    • 2012-01-05
    • 1970-01-01
    • 2011-09-29
    相关资源
    最近更新 更多