In my MainActivity has fragmentA
, fragmentB
, fragmentC
.
I want set fragmentA
and fragmentB
orientation to portrait but fragmentC
to landscape.
If the Manifest is set to portrait like this:
<activity android:name=".MainActivity" android:label="@string/app_name" android:screenOrientation="portrait" />
all fragment orientations are portrait.
How would I set the different orieantation of each fragment?
Try this in OnCreateView(View view)
of particular fragment,
//ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
//ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
getActivity()setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
Please add this line in oncreate () in fragment A and B
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
and add this line in oncreate() in fragment C
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
its working for me and I hope it will help you!