AlertDialog显示景观户型查看与取向景观 [英] AlertDialog Displays Landscape-Sized View with Orientation in Landscape

查看:194
本文介绍了AlertDialog显示景观户型查看与取向景观的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序的主要活动是在清单中设置为始终处于纵向视图。这工作得很好,当我加载应用到平板电脑。

然而,当我用我的菜单按钮,然后点击设置,打开一个 AlertDialog 是膨胀的XML布局,平板电脑将显示左侧2/3或所以整个对话。它的其余部分进入屏幕以外的权利。这种情况下,只有当我在平板电脑上安装我的应用程序,同时保持它在横向模式下,或者如果我把平板电脑为横向模式,而应用程序没有运行(即使我回去肖像,然后点击应用程序)出现。该对话框甚至要求 this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); ,以确保它保持在纵向(尽管问题仍然存在与此呼叫或没有)

在换句话说,这样的 AlertDialog 被显示在纵向视图是,它是吹了一个横向视图(因此它的一些云屏幕外),甚至虽然 AlertDialog 是纵向的实际方向,像它应该是。

(我道歉,如果上述措辞令人困惑 - 问我澄清任何事情,如果需要的话)

那么,为什么平板电脑做到这一点?我已经在少数的Andr​​oid手机进行了测试,这不会发生,所以我不明白为什么平板电脑将做到这一点。

便笺:

  • 这甚至不是发生了眼前这个 AlertDialog 要么..我的最终用户许可协议,在该应用程序的启动显示(另一个 AlertDialog )也,如果我开始在横向模式下的应用程序会出现这样的。

  • 我甚至允许景观的实用性通过摆脱所有的调用指定人像/风景模式,而平板电脑仍然在耗费关屏时,在纵向视图只是平板举行对话,但而不是手机。

编辑:

这code行之有效的手机,但平板电脑的问题仍然存在。如果我取消 dialog.show(); 下面,平板电脑和电话上显示我想要的尺寸,但在黑暗中,而不是调暗的主屏幕。任何想法?

调用函数做这样的:

 的ShowDialog(EXAMPLE_CASE);
 

函数被调用的调用函数:

 保护对话框onCreateDialog(最终诠释的id){
        对话对话框;
        AlertDialog.Builder建设者=新AlertDialog.Builder(本);

        显示显示= getWindowManager()getDefaultDisplay()。
        INT mwidth = display.getWidth();
        INT mheight = display.getHeight();

        WindowManager.LayoutParams LP =新WindowManager.LayoutParams();

        开关(ID){
        //什么的例子我所有的情况下,看起来像(有太多的复制)
        案例EXAMPLE_CASE:

            builder.setTitle(示例)
            .setMessage(示例消息)
            .setPositiveButton(OK,新DialogInterface.OnClickListener(){
                公共无效的onClick(DialogInterface dialoginterface,int i)以{
                    dialoginterface.dismiss();
                    的ShowDialog(DIALOG_CHOICE);
                }
            })
           .setCancelable(假);

            对话框= builder.create();

            打破;
        }


        如果(对话!= NULL){

            lp.copyFrom(dialog.getWindow()的getAttributes());
            lp.width = mwidth;
            lp.height = mheight;
            lp.x = mwidth;
            //lp.y = mheight;
            lp.dimAmount = 0.0;
            //dialog.show();
            。dialog.getWindow()setAttributes(LP);
            。dialog.getWindow()addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);

            dialog.setOnDismissListener(新OnDismissListener(){
                @覆盖
                公共无效onDismiss(DialogInterface对话){
                    removeDialog(ID);
                }
            });
        }

    返回对话框;
}
 

解决方案

您可以尝试让屏幕的尺寸是这样的:

 显示显示= getWindowManager()getDefaultDisplay()。
INT mwidth = display.getWidth();
INT mheight = display.getHeight();
 

再修改对话框是这样的:

  AlertDialog.Builder ADB =新AlertDialog.Builder(本);
对话D = adb.setView(新景(本))创建()。
//(即新的视图只是在那里有什么事情,可以长到足够大到覆盖整个屏幕的对话框中。)

d.show();

WindowManager.LayoutParams LP =新WindowManager.LayoutParams();
lp.copyFrom(d.getWindow()的getAttributes());
lp.width = mwidth;
lp.height = myheight;

//更改屏幕窗口的位置
lp.x = mwidth / 2; //设置这些值,以什么为你工作;可能喜欢我在这里
lp.y = mheight / 2; //一半屏幕的宽度和高度,因此它在中心

//设置背景的朦胧水平
lp.dimAmount = 0.1F; //更改此值或多或少的调光

。d.getWindow()setAttributes(LP);

//添加一个模糊/朦胧的标志
d.getWindow()addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND | WindowManager.LayoutParams.FLAG_DIM_BEHIND)。
 

另外,你说你正在膨胀的自定义布局。您是否尝试过与 layout_height layout_width 在该布局的意见,看看是否有差别?<修修补补/ P>

My app's main activity is set in the manifest to always be in portrait view. This works fine when I load the app onto the tablet.

However, when I use my menu button and click "Setup", which opens an AlertDialog that inflates an xml layout, the tablet will display the left 2/3 or so of the entire dialog. The rest of it goes offscreen to the right. This case only occurs if I install my app on the tablet while holding it in landscape mode or if I turn the tablet to landscape mode while the app is not running (even if I go back to Portrait and click on the app). The dialog even calls this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); to make sure it stays in portrait (even though the problem persists with this call or not).

In other words, the way the AlertDialog is being displayed in portrait view is that it is blowing up a landscape view (and thus some of it goes offscreen), even though the actual orientation of the AlertDialog is portrait, like it should be.

(I apologize if the wording above was confusing - ask me to clarify anything if needed.)

So why would the tablet do this? I've tested it on a few android mobile phones and this doesn't happen, so I don't understand why the tablet will do this.

SIDE NOTES:

  • This isn't even occurring for just this AlertDialog either.. my EULA that displays at the start of the app (another AlertDialog) also appears this way if I start the app in landscape mode.

  • I've even allowed the usability of landscape by getting rid of all calls to specify portrait/landscape mode, and the tablet is still expending the dialog off-screen when held in portrait view on just the tablet, but not the phones.

EDIT:

This code works well on the phone, but the tablet problem still persists. If I uncomment dialog.show(); below, the tablet and phone display the dimensions I want, but on blackness instead of the dimmed main screen. Any ideas?

Calling function does this:

showDialog(EXAMPLE_CASE);

Function that gets called by the calling function:

protected Dialog onCreateDialog(final int id) {
        Dialog dialog;
        AlertDialog.Builder builder = new AlertDialog.Builder(this);

        Display display = getWindowManager().getDefaultDisplay(); 
        int mwidth = display.getWidth();
        int mheight = display.getHeight();

        WindowManager.LayoutParams lp = new WindowManager.LayoutParams();

        switch(id) {
        // Example of what all my cases look like (there were way too many to copy)
        case EXAMPLE_CASE:

            builder.setTitle("Example")
            .setMessage("Example message")
            .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialoginterface,int i) {
                    dialoginterface.dismiss();
                    showDialog(DIALOG_CHOICE);
                }
            })
           .setCancelable(false);

            dialog = builder.create();

            break;
        }


        if (dialog != null) {

            lp.copyFrom(dialog.getWindow().getAttributes());
            lp.width = mwidth;
            lp.height = mheight;
            lp.x = mwidth;
            //lp.y = mheight;
            lp.dimAmount=0.0f;
            //dialog.show();
            dialog.getWindow().setAttributes(lp);
            dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);

            dialog.setOnDismissListener(new OnDismissListener() {
                @Override
                public void onDismiss(DialogInterface dialog) {
                    removeDialog(id);
                }
            });
        }

    return dialog;
}

解决方案

You could try getting the screen dimensions like this:

Display display = getWindowManager().getDefaultDisplay(); 
int mwidth = display.getWidth();
int mheight = display.getHeight();

And then alter the Dialog like this:

AlertDialog.Builder adb = new AlertDialog.Builder(this);
Dialog d = adb.setView(new View(this)).create();
// (That new View is just there to have something inside the dialog that can grow big enough to cover the whole screen.)

d.show();

WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.copyFrom(d.getWindow().getAttributes());
lp.width = mwidth;
lp.height = myheight;

//change position of window on screen
lp.x = mwidth/2; //set these values to what work for you; probably like I have here at
lp.y = mheight/2;        //half the screen width and height so it is in center

//set the dim level of the background
lp.dimAmount=0.1f; //change this value for more or less dimming

d.getWindow().setAttributes(lp);

//add a blur/dim flags
d.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND | WindowManager.LayoutParams.FLAG_DIM_BEHIND);

Also, you say you are inflating a custom layout. Have you tried tinkering with the layout_height and layout_width of the views in that layout to see if that makes a difference?

这篇关于AlertDialog显示景观户型查看与取向景观的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆