如何在Android中更改片段的方向?

Nik*_*Nik 5 android screen-orientation orientation-changes android-fragments

我已经设法在我的活动中更改了片段的方向.旋转设备时,方向会发生变化.

现在,当我点击片段中的按钮时,我想要相同的功能.即当我点击肖像布局和签证上的按钮时,我想从纵向模式更改为LandScape模式.

我用了

getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
Run Code Online (Sandbox Code Playgroud)

    getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
Run Code Online (Sandbox Code Playgroud)

分别.

但这使自动旋转功能停止工作.我该如何解决这个问题?

New*_*wts 0

请尝试这个

             <activity 
              android:name="<class name with package>"
                   android:label="@string/app_name"
                 android:theme="@android:style/Theme.NoTitleBar"
                 android:configChanges="orientation|keyboardHidden"
                android:screenOrientation="portrait">
Run Code Online (Sandbox Code Playgroud)