Rotate the Activity with click on a Button

独自空忆成欢 提交于 2019-12-13 07:08:39

问题


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!


回答1:


setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

or

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);


来源:https://stackoverflow.com/questions/21363021/rotate-the-activity-with-click-on-a-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!