How to make SurfaceView always horizontal?

I use SurfaceView to draw some things using canvas. The problem is that I want to show everything horizontally by default and save it that way, regardless of the position of the device. I do not use an XML layout file to display SurfaceView; instead, I have a class that extends SurfaceView, and I'm doing setContentView(new Panel(this));to show it.

Thank you for your help.

+3
source share
1 answer

Your problem is that the action will want to rotate depending on the position of the device or keyboard (depending on which device it is). If you want the activity to ignore the rotation, add android:screenOrientation="portrait"or android:screenOrientation="landscape"to your manifest for this action. You can also add android:configChanges="keyboardHidden|orientation"to this activity, so Android is not worried about killing and re-creating activity when the user changes orientation.

See here and here for sample projects related to this.

+6
source

Source: https://habr.com/ru/post/1743642/


All Articles