安卓:允许纵向和横向的平板电脑,但手机强迫肖像?纵向、肖像、横向、平板

由网友(凉墨)分享简介:我想平板电脑能在纵向和横向(sw600dp或更高)显示,但手机只限于肖像。我找不到任何方法来有条件地选择一个方向。有什么建议?I would like tablets to be able to display in portrait and landscape (sw600dp or greater), but p...

我想平板电脑能在纵向和横向(sw600dp或更高)显示,但手机只限于肖像。我找不到任何方法来有条件地选择一个方向。有什么建议?

I would like tablets to be able to display in portrait and landscape (sw600dp or greater), but phones to be restricted to portrait only. I can't find any way to conditionally choose an orientation. Any suggestions?

推荐答案

下面是一个使用的资源和大小预选赛的。

Here's a good way using resources and size qualifiers.

放入RES /值bools.xml或任何这种布尔资源(文件名不事这里):

Put this bool resource in res/values as bools.xml or whatever (file names don't matter here):

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

将这个之一RES /价值观sw600dp和RES /价值观XLARGE:

Put this one in res/values-sw600dp and res/values-xlarge:

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

然后,在你的活动的onCreate方法,你可以这样做:

Then, in the onCreate method of your Activities you can do this:

    if(getResources().getBoolean(R.bool.portrait_only)){
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }

设备是超过600 DP的最小宽度方向,或X大的pre-的Andr​​oid 3.2设备(平板电脑,主要)会像正常的

阅读全文

相关推荐

最新文章