【问题标题】:Lock Fragment rotation to Portrait?将片段旋转锁定为纵向?
【发布时间】:2014-05-20 21:44:17
【问题描述】:

我尝试将找到的这段代码 here 放入我的类代码中,但我无法让它工作。这是我正在使用的代码:

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;
}
}

如果有人可以指导我如何/在哪里将代码放在超链接中以使用上面的代码,以使片段不旋转并保持纵向,这对我学习非常有帮助。

谢谢!

【问题讨论】:

    标签: java android android-fragments screen-rotation


    【解决方案1】:

    自从发布此消息以来已经有一段时间了,但是这里的答案对我有帮助。

    在您的onCreateView 中为您想成为肖像的每个片段添加 getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    如果您需要 Landscape,只需将 SCREEN_ORIENTATION_PORTRAIT 更改为 SCREEN_ORIENTATION_LANDSCAPE

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多