如何在活动中设置片段的不同方向? [英] How to set different orientation of fragment in activity?

查看:73
本文介绍了如何在活动中设置片段的不同方向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的MainActivity中,有 fragmentA fragmentB fragmentC .

In my MainActivity has fragmentA, fragmentB, fragmentC.

我想将 fragmentA fragmentB 方向设置为纵向,而将 fragmentC 设置为横向.

I want set fragmentA and fragmentB orientation to portrait but fragmentC to landscape.

如果清单"设置为纵向:

If the Manifest is set to portrait like this:

<activity android:name=".MainActivity" android:label="@string/app_name" android:screenOrientation="portrait" />

所有片段方向均为纵向.

all fragment orientations are portrait.

我如何设置每个片段的不同排列方式?

How would I set the different orieantation of each fragment?

推荐答案

在特定片段的 OnCreateView(View view)中尝试此操作

Try this in OnCreateView(View view) of particular fragment,

//ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE

  getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

//ActivityInfo.SCREEN_ORIENTATION_PORTRAIT

  getActivity()setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

这篇关于如何在活动中设置片段的不同方向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆