我如何获得的屏幕尺寸编程在机器人 [英] How do I get the ScreenSize programmatically in android

查看:106
本文介绍了我如何获得的屏幕尺寸编程在机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Android的屏幕尺寸定义为普通大XLARGE等。

Android defines screen sizes as Normal Large XLarge etc.

它在不同文件夹的静态资源之间自动选择。我需要我的Java code对当前设备此数据。该DisplayMetrics只提供关于当前设备的密度信息。关于屏幕尺寸没有什么用。

It automatically picks between static resources in appropriate folders. I need this data about the current device in my java code. The DisplayMetrics only gives information about the current device density. Nothing is available regarding screen size.

我没有找到屏幕大小枚举中的grep code <一个href="http://grep$c$c.com/file/repo1.maven.org/maven2/com.android/common/r16/com/android/resources/ScreenSize.java?av=h#ScreenSize">here 然而,这似乎并没有提供给我的4.0 SDK。有没有一种方式来获得这些信息?

I did find the ScreenSize enum in grep code here However this does not seem available to me for 4.0 SDK. Is there a way to get this information?

推荐答案

复制并粘贴此code到活动,并在执行时它会吐司设备的屏幕尺寸类别。

Copy and paste this code into your Activity and when it is executed it will Toast the device's screen size category.

int screenSize = getResources().getConfiguration().screenLayout &
        Configuration.SCREENLAYOUT_SIZE_MASK;

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

这篇关于我如何获得的屏幕尺寸编程在机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆