Android - Lock orientation to two directions only

2019-02-12 20:11发布

How can make my android application to be Landscape or portrait but without the reverse directions?

Meaning that I want to enable SCREEN_ORIENTATION_PORTRAIT and SCREEN_ORIENTATION_LANDSCAPE but to disable SCREEN_ORIENTATION_REVERSE_LANDSCAPE and SCREEN_ORIENTATION_REVERSE_PORTRAIT.

Thanks

2条回答
劳资没心,怎么记你
2楼-- · 2019-02-12 20:35

I had the same problem/feature request in my camera app, and found this post:

android camera surfaceview orientation

In changeRotation just comment ORIENTATION_PORTRAIT_INVERTED and ORIENTATION_LANDSCAPE_INVERTED, and create a method rotateViews(int degrees) to rotate all of the images(buttons) of your layout when switching between regular landscape/portrait.

Also,

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

worked better for me than

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR | ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
查看更多
Melony?
3楼-- · 2019-02-12 20:40
查看更多
登录 后发表回答