如何使一个警告对话框充满90%的屏幕尺寸? [英] How to make an alert dialog fill 90% of screen size?

查看:165
本文介绍了如何使一个警告对话框充满90%的屏幕尺寸?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以创建和显示自定义警告对话框得很好,但即便如此我也机器人:layout_width /身高=FILL_PARENT在弹出的对话框XML它只有那么大作为内容

I can create and display a custom alert dialog just fine but even so I have android:layout_width/height="fill_parent" in the dialog xml it is only as big as the contents.

我要的是对话,填补了整个屏幕,除了20像素的也许填充。 然后就是对话的一部分的图像将自动延伸到与FILL_PARENT完整的对话框大小。

What I want is dialog that fills the entire screen except maybe a padding of 20 pixel. Then the image that is part of the dialog would automatically stretch to the full dialog size with fill_parent.

非常感谢,费边

推荐答案

据Android平台开发戴安娜Hackborn在<一个href="http://groups.google.com/group/android-developers/browse_thread/thread/f0bb813f643604ec">this讨论组后,对话框的设置窗口的顶部水平布置的宽度和高度,以 WRAP_CONTENT 。为了使对话框变大,你可以设置这些参数,以 MATCH_PARENT

According to Android platform developer Dianne Hackborn in this discussion group post, Dialogs set their Window's top level layout width and height to WRAP_CONTENT. To make the Dialog bigger, you can set those parameters to MATCH_PARENT.

演示code:

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

    WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
    lp.copyFrom(d.getWindow().getAttributes());
    lp.width = WindowManager.LayoutParams.MATCH_PARENT;
    lp.height = WindowManager.LayoutParams.MATCH_PARENT;
    d.show();
    d.getWindow().setAttributes(lp);

请注意,该属性设置对话框显示之后。该系统是挑剔的,当他们被设置。 (我想这是所示的对话框,什么布局引擎必须将他们的第一次。)

Note that the attributes are set after the Dialog is shown. The system is finicky about when they are set. (I guess that the layout engine must set them the first time the dialog is shown, or something.)

这将是更好地扩大Theme.Dialog要做到这一点,那么你就不会发挥什么时候打电话setAttributes一个猜谜游戏。 (虽然这是一个更多的工作有对话框会自动采取适当的亮或暗的主题,或蜂窝的Holo主题,这可以根据<一做href="http://developer.android.com/guide/topics/ui/themes.html#SelectATheme">http://developer.android.com/guide/topics/ui/themes.html#SelectATheme )

It would be better to do this by extending Theme.Dialog, then you wouldn't have to play a guessing game about when to call setAttributes. (Although it's a bit more work to have the dialog automatically adopt an appropriate light or dark theme, or the Honeycomb Holo theme. That can be done according to http://developer.android.com/guide/topics/ui/themes.html#SelectATheme )

这篇关于如何使一个警告对话框充满90%的屏幕尺寸?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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