0

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

4

1 回答 1

1

使用方法检查设备是否为平板电脑,如果是则强制定向。

// 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);
于 2013-02-12T20:42:57.757 回答