简体   繁体   English

如何通过可编程方式将屏幕旋转为横向(或纵向)?

[英]How to rotate the screen to landscape (or portrait) by programmable way?

How to rotate the screen to landscape (or portrait) by programmable way? 如何通过可编程方式将屏幕旋转为横向(或纵向)? I am trying to make it independent when user rotates the screen. 我试图在用户旋转屏幕时使其独立。

Is it possible thing ? 有可能吗?

Thanks in advance. 提前致谢。

Try this: 尝试这个:

Activity.setRequestedOrientation() 

with these parameters: 使用这些参数:

ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
ActivityInfo.SCREEN_ORIENTATION_PORTRAIT

Check this for further reference 检查这个以供进一步参考

You can try with the sample below... 您可以尝试下面的示例...

if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
    // You can set the value initially by
    // ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED. Once set it
    // retains it's value. The View will be rendered in the specified
    // orientation using the code below.
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}

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

相关问题 屏幕方向被强制设置为纵向,但倾斜时活动仍将旋转为横向! 如何强制人像模式? - Screen orientation forced to portrait, but still, the activities will rotate to landscape when tilted!! How to force portrait mode? 如何在纵向/横向更改中旋转imageView - How to rotate a imageView in portrait / landscape changing 如何在Android OpenCV 3中将风景图像旋转为人像 - How rotate a Landscape Image to Portrait in Android OpenCV 3 从肖像活动返回到风景活动时,屏幕旋转3次 - Screen rotate 3 times when back to landscape activity from portrait activity 如何识别屏幕是在Kivy中是纵向还是横向 - How to identify whether the screen is in Portrait or Landscape in Kivy 如何在Android的横向或纵向视图中跟踪屏幕? - how to track the screen in landscape or portrait view in android? 仿真器处于纵向模式,而屏幕处于横向模式 - Emulator is in portrait but screen is in Landscape 从横向到纵向旋转时,Phonegap / HTML5和Android屏幕调整大小问题 - Phonegap/HTML5 and Android screen resize issue on rotate from landscape to portrait 如何在反向纵向和反向横向模式下锁定屏幕方向 - How to lock screen orientation in reverse portrait and reverse landscape mode 如何在Android Libgdx中设置纵向的主屏幕和横向的其他屏幕? - How to set home screen in portrait and other screens in landscape in android Libgdx?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM