简体   繁体   English

对话框本身会更改方向。 如何将对话框的方向固定为横向

[英]Dialog changes the orientation by itself. How to fix the orientation of a dialog to landscape

I am showing a custom dialog in an activity of which the orientation is set to landscape. 我正在将方向设置为横向的活动中显示自定义对话框。 But the orientation is getting changed to portrait mode from the inital landscape(only the dialog, below activity remains in landscape mode). 但是方向已从原始横向更改为纵向模式(仅活动下方的对话框保留为横向模式)。 This is happening without any outside action like tilting the tablet or something. 这是在没有任何外部动作(例如倾斜数位板或其他东西)的情况下发生的。

I could not find any help in fixing the orientation of dialog anywhere. 我在任何地方都无法确定对话框的方向。

Any ideas? 有任何想法吗?

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();

This is the code used for showing the dialog. 这是用于显示对话框的代码。

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

This is the xml element parent tag used. 这是使用的xml元素父标记。

If you are using an Activity as a dialog then you can set 如果您使用“活动”作为对话框,则可以设置

android:screenOrientation="landscape" 

in your manifest file. 在清单文件中。

If you are using custom dialog then you can use 如果使用自定义对话框,则可以使用

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

before you use setContentView(); 在使用setContentView()之前; method. 方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM