有没有办法以编程方式设置反向移植的方向?

时间:2018-04-20 10:09:11

标签: java android screen-orientation

  1. 有没有办法以编程方式设置反转肖像的方向?
  2. 我可以禁用方向更改动画吗?

2 个答案:

答案 0 :(得分:1)

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

希望这有帮助

  

https://developer.android.com/reference/android/content/pm/ActivityInfo.html#SCREEN_ORIENTATION_LANDSCAPE

如果您需要更多参考,那么 Change Screen Orientation programmatically using a Button

答案 1 :(得分:1)

是的,使用

您可以通过以下方式进行更改:

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

检测方向变化实施

 OrientationEventListener mOrientationListener;

您可以找到更多帮助here

或者更好的方法是在AndroidManifest.xml文件中强制屏幕方向,例如:

<activity android:name=".DisableScreenRotationAndroid" android:screenOrientation="landscape">
相关问题