Allow rotation/landscape in one fragment

前端 未结 6 1301
旧巷少年郎
旧巷少年郎 2020-12-05 03:05

My app has a single Activity with a FragmentPagerAdapter with four fragments (Using the ViewPagerIndicator library). One of these fragments has designs for both a separate p

6条回答
  •  心在旅途
    2020-12-05 03:20

    If you want to change it to landscape for specific fragment, consider this. Remember to change it back to stopsActivityInfo.SCREEN_ORIENTATION_PORTRAIT on fragment's lifecycle stop

    @Nullable
    @Override
    public View onCreateView(@NotNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        requireActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        return inflater.inflate(R.layout.YOUR_LAYOUT, container, false);
    }
    

提交回复
热议问题