首页 > 解决方案 > 如何在android清单文件中设置纵向和横向

问题描述

纵向模式正常工作,横向未显示。

android:screenOrientation="portrait" // 这里我需要同时显示纵向和横向。

标签: androidandroid-studioandroid-manifest

解决方案


参考文档:点击这里

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

   // Fragment locked in portrait screen orientation
   getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);    

   // Fragment locked in landscape screen orientation
   getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

   // Fragment screen orientation normal both portait and landscape       
   getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
}

希望,这将为您提供预期的解决方案。


推荐阅读