Android resource size qualifier

 ̄綄美尐妖づ 提交于 2019-12-08 06:35:27

问题


I unable to get the values from "values-sw480dp" nor on my sony Xperia device which is 480 x 854 neither on Samsung galaxy tab which is 600 x 1024. But able to get on Motorola Xoom which is 1280 x 752.

e.g res/values-sw480dp/strings.xml/

<string name="hello_world">hello world</string>

The values on respective devices

Sony Xperia ----> @2131034113

Samsung ----> @2131034113

on xoom ---> hello world

Can any one explain me this behavior, why Sony Xperia and Samsung has "@2131034113" value.

Thank you in advance


回答1:


According to http://developer.android.com/guide/topics/resources/providing-resources.html, sw480dp means «smallest side of screen must be at least 480 dp». Now dp is a «pixel on a 160 dpi screen», so actual size of e.g. Xperia in dp would be I guess 320 x 569 (provided it's a hdpi device).

To get device screen size in dp you need to know abstracted density class (ldpi=120, mdpi=160, hdpi=240, xhdpi=320). For the above Xperia screen the calculation is: (480*160/240) x (854*160/240), where 160 is the base density (it's where 1 dp actually equal to one pixel) and 240 is device abstracted density.



来源:https://stackoverflow.com/questions/12638518/android-resource-size-qualifier

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!