有没有办法以编程方式设置方向以反转肖像?

Is there a way to set programmatically the orientation to reverse portait?

  1. 有没有办法以编程方式将方向设置为反转纵向?
  2. 我可以禁用方向改变动画吗?
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

希望对您有所帮助

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

如果您需要更多参考资料 使用按钮以编程方式更改屏幕方向

是的,使用

您可以通过以下方式更改它:

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

检测方向变化实施

 OrientationEventListener mOrientationListener;

您可以找到更多帮助here

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

<activity android:name=".DisableScreenRotationAndroid" android:screenOrientation="landscape">