2017-01-27 2 views
1

화면이 180도 회전하는 것이 왜 구성 변경으로 계산되지 않으므로 Activity.onCreate()!을 (를) 트리거하지 않습니다. 그래서 나는 카메라의 방향을 바꿀 수 없다! 90도 회전하면 설정이 매번 변경됩니다. 내 매니페스트에 configChanges이없고 orientation 속성이 있기 때문에 소스 코드를 생략합니다. 활동에는 특별한 것도 없습니다. 이것이 의도 된 동작 인 것으로 보이지만 공식 정보를 찾지 못했습니다.왜 화면의 180도 회전이 구성 변경으로 계산되지 않습니까?

장치 : 하드웨어 넥서스 5 배

플랫폼 : 안드로이드 7.1.1

매니페스트 :

<supports-screens 
    android:anyDensity="true" 
    android:largeScreens="true" 
    android:normalScreens="true" 
    android:smallScreens="false" 
    android:xlargeScreens="true" /> 

<application 
    android:name="xyz.MyApp" 
    android:allowBackup="true" 
    android:backupAgent=".provider.MyBackupAgent" 
    android:hardwareAccelerated="true" 
    android:icon="@mipmap/ic_launcher" 
    android:label="@string/app_name" 
    android:largeHeap="true" 
    android:restoreAnyVersion="true" 
    android:theme="@style/AppTheme" 
    android:uiOptions="splitActionBarWhenNarrow" 
    tools:replace="android:icon" > 

<activity android:name="xyz.MyActivity" 
     android:label="asdf" 
     android:theme="@style/Theme" /> 

styles.xml :

<style name="Theme" parent="Theme.AppCompat.NoActionBar"> 
    <item name="actionBarIconColor">#fff</item> 
    <item name="actionBarInsetStart">@dimen/keyline_2</item> 
</style> 

스타일-V19 .xm L : 당신은 AndroidManifest.xml 로 활동에 대한 android:screenOrientation="fullSensor"를 지정해야합니다

<style name="Theme" parent="Theme.AppCompat.NoActionBar"> 
    <item name="actionBarIconColor">#fff</item> 
    <item name="actionBarInsetStart">@dimen/keyline_2</item> 
    <item name="android:windowTranslucentStatus">true</item> 
    <item name="android:windowTranslucentNavigation">true</item> 
</style> 
+0

을 사용할 수 있습니다 : 당신은 (180)에 의해 회전 후 뷰의 일부를 변경하려는 경우 당신은 OrientationEventListener

샘플 사용할 수 있습니다 그것을 세로 (또는 가로)로 유지하므로 아무 것도 필요하지 않습니다. –

+0

글쎄,하지만 그것은 카메라 미리보기 거꾸로! – WindRider

답변

2

here 기본 방향은 역 세로 방향을 무시 sensor입니다 설명했다. fullSensor은 모든 4 방향을 허용합니다.

업데이트 : 위의 대답으로 문제가 해결되지 않습니다. 중 요한 문제는 방향을 180 도로 변경하면 (즉, 가로 방향에서 가로 방향으로) 활동이 다시 생성되지 않는다는 것입니다. 그것은 예상 된 행동입니다. 흔히 풍경을위한 레이아웃은 역 경관을위한 레이아웃과 다르지 않습니다. 180도 회전하기 때문에

final WindowManager mWindowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE); 

OrientationEventListener orientationEventListener = new OrientationEventListener(this, 
       SensorManager.SENSOR_DELAY_NORMAL) { 
      @Override 
      public void onOrientationChanged(int orientation) { 
       if (orientation == ORIENTATION_UNKNOWN) { 
        return; 
       } 
       Display display = mWindowManager.getDefaultDisplay(); 
       int rotation = display.getRotation(); 
       if (rotation != mLastRotation) { 
        // do something with your views 
        mLastRotation = rotation; 
       } 
      } 
     }; 

if (orientationEventListener.canDetectOrientation()) { 
    orientationEventListener.enable(); 
} 

당신의 minSdk 인 경우

은 17 세 이상 당신은 또한 DisplayListener#onDisplayChanged 콜백에게

+0

완전히 이해가되지만 여전히 작동하지 않습니다. – WindRider

+0

@WindRider 활동 및 AndroidManifest.xml 코드로 질문을 업데이트 할 수 있습니까? – nnesterov

+0

나는 어떤 활동 으로든 그것을 재현 할 수 있다고 확신한다. 나는 다른 활동과 다른 앱으로 그것을했다. 이것은 플랫폼에 기반한 행동으로 보입니다. – WindRider