[英]How to change the Orientation for fragments in Android?
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.
即当我点击肖像布局和签证上的按钮时,我想从纵向模式更改为LandScape模式。
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">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.