0

I have this Activity container that will change fragments accordingly during the usage of the application.

public class MyTravelogueActivity extends SherlockFragmentActivity {
    //codes here
}

Can I ask if it's possible to check that if the current Fragment is of a MapFragment class, i want to change the orientation to LANDSCAPE only? And when I click on the back button or navigate somewhere else, orientation should go back to portrait. Currently all the fragments are displayed in portrait mode...

lyk
  • 1,578
  • 5
  • 25
  • 49

1 Answers1

0

Yes it's possible. I believe the user should have the option to choose the desired orientation, but if you want to do that, you can use the setRequestedOrientation method from the activity class. Didn't test if, but something like this should work: On the onResume method of your MapFragment, you can use

getActivity().setRequestedOrientation(<Landscape Orientation>)

On the onPause method of your MapFragment, you can use

getActivity().setRequestedOrientation(<Portrait Orientation>)

Replace <Landscape Orientation> and <Portrait Orientation> with the desired option from here.

Marcelo
  • 1,471
  • 3
  • 19
  • 22