Question

What I am trying to do is to set the activity orientation manually at preferences screen. Lets say the default orientation is 0(regular portrait orientation) and user can go to preferences and choose lets say 180(or 90, 270). After this the activity orientation should change to the chooser option. There are methods to set portrait or landscape orientation but I cant figure out how to rotate the activity by degrees.

Était-ce utile?

La solution

You will need to call youractivity.setRequestedOrientation(int orientation).

This parameter is not the degrees, it will be a constant from ActivityInfo.

This page has some of the constants, but I guess the one you want is this.

Autres conseils

You can use mainActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT); to rotate by 180 degree if you are currently in portrait mode or mainActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE); to rotate by 180 from Landscape mode.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top