简体   繁体   中英

Lock Fragment rotation to Portrait?

I've tried to put this code which was found here into my Class code but I couldn't get it to work. Here's the code I'm working with:

public class Details extends Fragment {

public void onCreate (Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {

    View rootView = inflater.inflate(R.layout.details, container, false);

  return rootView;
}
}

If someone could guide me how/where to put the code in the Hyperlink to work with the code above in order for the Fragment to not rotate and stay in Portrait that would be extremely helpful for me to learn.

Thank you!

its been a while since this is posted, but here is answer which helped me in my case.

In your onCreateView for each Fragment you want to be Portrait add getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

If you need Landscape just change SCREEN_ORIENTATION_PORTRAIT to SCREEN_ORIENTATION_LANDSCAPE

Hope it helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM