Rotate the Activity with click on a Button

2019-09-06 19:13发布

I am using this CODE to disable the auto rotate in my App:

            android:screenOrientation="portrait"

What I want is to write a CODE inside my Activity to make the App on portrait or landscape as the user want by clicking a button and save it in SharedPreferences.

I am already made layout and layout-land with different design but as i disabled it in my Manifest its is not showing up, Cause i want the users chose what they want!

Thanks for any Help

UPDATE

    /** Here is the Rotation Button */
View.OnClickListener mb2 = new View.OnClickListener() {
    public void onClick(View v) {
        startActivity(new Intent(".ABOUT"));
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

    }
};

It doesn't work this way!

2条回答
Explosion°爆炸
2楼-- · 2019-09-06 19:43
     iv_fullScreenVideo.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            int orientation = context.getResources().getConfiguration().orientation;

            switch (orientation) {

                case Configuration.ORIENTATION_LANDSCAPE:

                    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

                    break;

                case Configuration.ORIENTATION_PORTRAIT:

                    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

                    break;
            }

        }
    });
查看更多
看我几分像从前
3楼-- · 2019-09-06 19:50
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

or

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
查看更多
登录 后发表回答