清單檔案中的給下面的屬性,你的相機預覽活動 android:configChanges="keyboardHidden|orientation"
進行更關注屏幕閱讀this
<activity
android:name=".Your_Activity_Name"
android:configChanges="keyboardHidden|orientation"
android:label="@string/app_name" >
<intent-filter>
<!-- Your filter attributes if any. -->
</intent-filter>
</activity>
而在你的活動類重寫onConfigurationChanged
&做要緊(如您需要)定位模式(例如,橫向或縱向)像THIS_
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// Checks the orientation of the screen
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
Toast.makeText(this, "landscape", Toast.LENGTH_SHORT).show();
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
//Your code to do the other things in landscape mode...
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
Toast.makeText(this, "portrait", Toast.LENGTH_SHORT).show();
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
//Your code to do the other things in portrait mode...
}
}
我希望這將幫助你擺脫你的問題。
您是否嘗試過使用實際對話框而不是使用實際的對話框作爲對話框(在活動描述中使用android:theme =「@ android:style/Theme.Dialog」)開始新的活動?我懷疑這個僞造的對話框應該以通常的方式對方向改變做出反應,因爲你只在橫向鎖定相機活動。不幸的是,我現在無法自己嘗試。 – Audrius
還沒有試過呢。會很好,如果這樣的作品... – stoefln
不工作 - 只是試過了:無論我如何旋轉設備,對話框活動也顯示在橫向上 – stoefln