安卓:允许纵向和横向的平板电脑,但手机强迫肖像? [英] Android: allow portrait and landscape for tablets, but force portrait on phone?

查看:107
本文介绍了安卓:允许纵向和横向的平板电脑,但手机强迫肖像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想平板电脑能在纵向和横向(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设备(平板电脑,主要)会像正常的based~~V传感器和用户锁定旋转等。其他一切(手机,pretty的多)将是唯一的肖像。

Devices that are more than 600 dp in the smallest width direction, or x-large on pre-Android 3.2 devices (tablets, basically) will behave like normal, based on sensor and user-locked rotation, etc. Everything else (phones, pretty much) will be portrait only.

这篇关于安卓:允许纵向和横向的平板电脑,但手机强迫肖像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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