Search code examples
androidandroid-fragmentsandroid-orientation

Android: Orientation on fragments?


I have a menu with fragments instead of activities. Each fragment is full screen when is called. I want to be able to make for fragment1 - orientation portrait, fragment 2 - orientation landscape etc.. For activities is easy beacuse i can change them in the manifest, but how can i do on fragments?


Solution

  • Inside the onCreate of each fragment you have to call

    getActivity().setRequestedOrientation(requestedOrientation)
    

    that's will set the orientation of your Activity (se the Fragment orientation) to requestedOrientation. This is the only way. Fragment itself can not manage its orientation