有没有一种方法,如果用户使用的是平板电脑或手机来检查? 我有问题,我的倾斜功能和我的新平板电脑(变压器)
Is there a way to check if the user is using a tablet or a phone? I've got problems with my tilt function and my new tablet (Transformer)
正如前面提到过,你不想来检查设备是否是平板电脑或手机,但你想了解该设备的特点
As it has been mentioned before, you do not want to check whether the device is a tablet or a phone but you want to know about the features of the device,
大多数时间,片剂和电话之间的差在屏幕大小这就是为什么要采用不同的布局文件。这些文件都存储在 RES /布局 - <预选赛>
目录。您可以创建在directoy一个XML文件 RES /值时─<同一预选赛>
为您的每一个布局,并把一个int /布尔/字符串资源到其中来区分的布局使用。
Most of the time, the difference between a tablet and a phone is the screen size which is why you want to use different layout files. These files are stored in the res/layout-<qualifiers>
directories. You can create an XML file in the directoy res/values-<same qualifiers>
for each of your layouts and put an int/bool/string resource into it to distinguish between the layouts you use.
文件 RES /价值/ screen.xml
(假设 RES /布局/
包含您的布局文件手机)
File res/values/screen.xml
(assuming res/layout/
contains your layout files for handsets)
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="screen_type">phone</string>
</resources>
文件 RES /值-sw600dp / screen.xml
(假设 RES /布局sw600dp /
包含您的布局文件小喜欢的Nexus 7)
File res/values-sw600dp/screen.xml
(assuming res/layout-sw600dp/
contains your layout files for small tablets like the Nexus 7)
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="screen_type">7-inch-tablet</string>
</resources>
文件 RES /值-sw720dp / screen.xml
(假设 RES /布局sw720dp /
包含您的布局文件较大
File res/values-sw720dp/screen.xml
(assuming res/layout-sw720dp/
contains your layout files for large tablets like the Nexus 10):
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="screen_type">10-inch-tablet</string>
</resources>
现在画面类型是通过 R.string.screen_type
不变。
Now the screen type is accessible via the R.string.screen_type
constant.