根据进入Activity的手持方向锁定Activity的Orientation

在Activity的onCreate()中调用以下函数便可实现,须要注意的是Activity的setRequestedOrientation()方法须要传入的是ActivityInfo中的Orientation值。
private void lockActivityOrientation(){
        int orientation = getResources().getConfiguration().orientation;
        int activityOrientation = 0;
        if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
            activityOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
        } else {
            activityOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
        }
        setRequestedOrientation(activityOrientation);
    }
相关文章
相关标签/搜索