How to rotate the screen to landscape (or portrait) by programmable way?
How to rotate the screen to landscape (or portrait) by programmable开发者_如何学Python way? I am trying to make it independent when user rotates the screen.
Is it possible thing ?
Thanks in advance.
Try this:
Activity.setRequestedOrientation()
with these parameters:
ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
Check this for further reference
You can try with the sample below...
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
// You can set the value initially by
// ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED. Once set it
// retains it's value. The View will be rendered in the specified
// orientation using the code below.
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
精彩评论