开发者

How to rotate the screen to landscape (or portrait) by programmable way?

开发者 https://www.devze.com 2022-12-24 17:21 出处:网络
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.

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);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消