简体   繁体   English

Android:即使手机处于纵向模式,如何在横向模式下显示片段?

[英]Android: How to display fragment in landscape mode, even if the phone is in portrait mode?

There is a fragment, that is in portrait mode, then I replace that fragment with another, and I want it to be displayed in landscape mode, even if I hold my phone in portrait mode. 有一个片段处于纵向模式,然后我用另一个片段替换了该片段,即使我将手机置于纵向模式,我也希望它以横向模式显示。 (Both are in the same activity, and I don't want to change that.) If I simply put the layout file in the layout_land folder, than the app crashes. (两者都处于同一活动中,并且我不想更改它。)如果仅将布局文件放在layout_land文件夹中,则应用程序将崩溃。 I can't define it in a layout xml tag like android:screenorientation="landscape", because i must add and replace fragments programatically. 我无法在android:screenorientation =“ landscape”之类的xml布局标签中定义它,因为我必须以编程方式添加和替换片段。 Any idea? 任何想法?

您可能会向加速度计打底机提供虚假信息。它不是很漂亮,但是应该可以工作

Look at 看着

setRequestedOrientation(requestedOrientation);

Maybe it helps you. 也许对您有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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