1

everyone! My question is inverted version of How to lock fragment orientation without locking activity orientation? , but nothing from there have worked for me.

The point is, that I have a camera app, where camera preview lays in activity, and an overlay with settings and other stuff - in fragment, like this:

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

So, I want to lock camera preview orientation, while keeping overlay orientation unlocked (as in camera apps in samsung, or sony smartphones).

Thanks in advance.

Community
  • 1
  • 1
  • try there inside your fragment getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); //For Portrait getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);//For Landscape – Rakshit Nawani Apr 25 '16 at 10:54
  • @RakshitNawani it also locks fragment orientation :( – Сергей Дрымченко Apr 25 '16 at 11:07
  • So DON'T GIVE ORIENTATION TO YOUR ACTIVITY AND GIVE ORIENTATION TO THE FRAGMENTS – Rakshit Nawani Apr 25 '16 at 11:10
  • @RakshitNawani hm, but my question is exactly about your comment - how to give orientation exactly to fragment, not the activity. – Сергей Дрымченко Apr 25 '16 at 11:14
  • You can add any of the below line according to your need to change orientation inside your onCreateView of your Fragment . getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); //For Portrait getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE)‌​;//For Landscape It will change the orientation of the fragment accordingly . Try it once – Rakshit Nawani Apr 25 '16 at 11:16
  • @RakshitNawani feeling myself stupid already. your code put BOTH fragment and activity in selected orientation, so, rotating device dont't change fragment orientation. – Сергей Дрымченко Apr 25 '16 at 11:32

2 Answers2

0

You can handle configuration change by yourself by adding android:configChanges="orientation|screenSize" in a manifest.

So you have to override onConfigurationChanged().

Maxim G
  • 1,479
  • 1
  • 15
  • 23
0

In you manifest file

in any activity you want to set orientation of :) find this code and name of your activity.

<activity android:name=".MainActivity">

then add the attribute to this android:screenOrientation=""

So that you can get required orientation of any activity :) by default

Humza Malik
  • 343
  • 3
  • 14