[英]Dialog changes the orientation by itself. How to fix the orientation of a dialog to landscape
我正在將方向設置為橫向的活動中顯示自定義對話框。 但是方向已從原始橫向更改為縱向模式(僅活動下方的對話框保留為橫向模式)。 這是在沒有任何外部動作(例如傾斜數位板或其他東西)的情況下發生的。
我在任何地方都無法確定對話框的方向。
有任何想法嗎?
Dialog mDialog = new Dialog(MainActivity.this);
mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
mDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
mDialog.setContentView(R.layout.alert);
mDialog.show();
這是用於顯示對話框的代碼。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="300dip"
android:layout_height="300dip"
android:background="@drawable/alert_bg"
android:orientation="vertical" >
------------------------------
---------------------------
</LinearLayout>
這是使用的xml元素父標記。
如果您使用“活動”作為對話框,則可以設置
android:screenOrientation="landscape"
在清單文件中。
如果使用自定義對話框,則可以使用
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
在使用setContentView()之前; 方法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.