获取屏幕尺寸桶编程? [英] Get screen size bucket programatically?

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

问题描述

我要确定当前设备是否具有小型,中型,大型或XLARGE在code屏幕。我无法在SDK文档,这将有助于我得到的信息任何事情。所有方法/班我已经看过仅提供绝对的值(即屏幕大小像素,屏幕像素密度,等等)。

有没有办法告诉什么样的屏幕,我在code运行?

解决方案

我结束了使用布尔放置在不同的文件夹桶资源

。我只需要正常(小/中)和大(大/ XLARGE)画面之间进行区分,所以我这样做:

值/ bools.xml

 < XML版本=1.0编码=UTF-8&GT?;
<资源>
    <布尔名=screen_large>假< /布尔>
< /资源>
 

价值观大/ bools.xml

 < XML版本=1.0编码=UTF-8&GT?;
<资源>
    <布尔名=screen_large>真< /布尔>
< /资源>
 

然后,我只是叫<一href="http://developer.android.com/reference/android/content/res/Resources.html#getBoolean%28int%29"><$c$c>getBoolean(R.bool.screen_large)告诉屏幕是大还是不行。这种方式是100%到平台决定什么屏幕的设备了。

I want to determine whether the current device has a small, medium, large or xlarge screen in code. I can't find anything in the SDK docs that would help me get to that information. All the methods / classes I have looked at provide only absolute values (i.e. screen size in pixels, screen density, etc.).

Is there a way to tell what kind of screen I'm running on in code?

解决方案

I ended up using bool resources placed in the different bucket folders. I only needed to differentiate between normal (small / medium) and large (large / xlarge) screens, so I did this:

values/bools.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <bool name="screen_large">false</bool>
</resources>

values-large/bools.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <bool name="screen_large">true</bool>
</resources>

Then, I just call getBoolean(R.bool.screen_large) to tell whether the screen is large or not. This way it's 100% up to the platform decide what screen the device has.

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

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