Allow rotation/landscape in one fragment

前端 未结 6 1293
旧巷少年郎
旧巷少年郎 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:24

    Write some code in AndroidManifest.xml on the particular activity tag.

    android:configChanges="orientation|screenSize".
    

    And Write code in Fragment on onCreateView method,
    for Portrait:

    getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); 
    setRetainInstance(true);
    

    for Landscape:

    getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    setRetainInstance(true);
    

提交回复
热议问题