I have managed to change the Orientation for my fragment in my activity. The Orientation is changed when my device is rotated.
Now I want to same functionality when I click on a button in the fragment. ie I want to change from portrait mode to LandScape mode when I click on a button on the portrait layout and visa vera.
I used
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
and
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
respectively.
But this made the auto rotate functionality stop working. How can I fix this issue?
当你需要自动旋转时,使用getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
Please try this
<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">
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.