【问题标题】:How to lock activity orientation without locking fragment orientation?如何在不锁定片段方向的情况下锁定活动方向?
【发布时间】:2016-04-25 10:52:06
【问题描述】:

大家!我的问题是 How to lock fragment orientation without locking activity orientation? 的倒置版本,但从那里没有对我有用。

关键是,我有一个相机应用程序,其中相机预览处于活动状态,并带有设置和其他内容的覆盖 - 在片段中,如下所示:

<RelativeLayout    
android:id="@+id/main_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:weightSum="1">

<FrameLayout
    android:id="@+id/surfaceView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"

    />

<FrameLayout
    android:id="@+id/overlayContainer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    />

</RelativeLayout>

所以,我想锁定相机预览方向,同时保持覆盖方向解锁(如在三星或索尼智能手机中的相机应用中)。

提前致谢。

【问题讨论】:

  • 在你的片段里面试试 getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); //对于纵向 getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);//对于横向
  • @RakshitNawani 它还锁定片段方向:(
  • 所以不要给你的活动定位,而是给碎片定位
  • @RakshitNawani 嗯,但我的问题正是关于您的评论 - 如何准确地为片段而不是活动提供方向。
  • 您可以根据需要在 Fragment 的 onCreateView 中更改方向,添加以下任何行。 getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); //For Portrait getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE)‌​;//For Landscape 会相应地改变片段的方向。试一次

标签: android android-fragments android-orientation


【解决方案1】:

您可以通过在清单中添加android:configChanges="orientation|screenSize" 来处理配置更改by yourself

所以你必须覆盖onConfigurationChanged()

【讨论】:

【解决方案2】:

在你的清单文件中

在您想要设置方向的任何活动中:) 找到您的活动的代码和名称。

<activity android:name=".MainActivity">

然后将属性添加到这个 android:screenOrientation=""

这样您就可以获得任何活动的所需方向:) 默认情况下

【讨论】:

  • 是的,但它也锁定了片段方向:(
猜你喜欢
  • 2013-12-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多