繁体   English   中英

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

[英]How to change the Orientation for fragments in Android?

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

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

我用了

getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

    getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

分别。

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

当你需要自动旋转时,使用getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);

请试试这个

             <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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM