Portrait for phone, landscape for Tablet (Android-Layout)

后端 未结 5 1703
臣服心动
臣服心动 2020-11-30 04:09

So I\'m making an application for Android and I want to force Landscape orientation for tablets and Portrait orientation for phones. However, it seems as though I can only

5条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-30 04:34

    for people who used

    android:screenOrientation="nosensor"
    

    and did not work on it own I used it in addition to this snippet in my base activity

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        if (getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
                && (this.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) < Configuration.SCREENLAYOUT_SIZE_LARGE) {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        }else if((this.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE){
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        }
        super.onCreate(savedInstanceState);
    }
    

提交回复
热议问题