Setting the orientation for only 1 fragment in my activity while the rest is in portrait

Use the following code line in the fragment where you want a specific (in this case portrait) orientation.

getActivity().setRequestedOrientation(
            ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

If you want to have a orientation in a fragment, that is based on the way the user holds his device, then use the following code line.

getActivity().setRequestedOrientation(
                ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);

Hope, this will give you the intended solution.

Leave a Comment