有没有办法强制不同的设备不同的方向?

时间:2013-02-12 20:39:36

标签: android device-orientation

我希望我的应用程序始终在平板电脑上显示横向,但它应该在手机上旋转正常。有没有办法做到这一点(除了有2个不同的apks)?

1 个答案:

答案 0 :(得分:1)

使用check whether the device is a tablet的方法,然后使用force orientation,如果是的话。

// From https://stackoverflow.com/questions/5832368/tablet-or-phone-android
public boolean isTablet(Context context) {
    boolean xlarge = ((context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == 4);
    boolean large = ((context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE);
    return (xlarge || large);
}

// ...

// Do this from any Activity you do not wish to rotate on tablets:
if (isTablet(this))
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);