dialog居于底部并使得宽度占满整个屏幕宽度

来源:互联网 发布:mac怎么设置用户名 编辑:程序博客网 时间:2024/05/16 05:06
        imageDialog.show();        Window window = imageDialog.getWindow();        if (imageDialog != null && window != null) {            window.getDecorView().setPadding(0, 0, 0, 0);            WindowManager.LayoutParams attr = window.getAttributes();            if (attr != null) {                attr.height = ViewGroup.LayoutParams.WRAP_CONTENT;                attr.width = ViewGroup.LayoutParams.MATCH_PARENT;                attr.gravity = Gravity.BOTTOM;//设置dialog 在布局中的位置                window.setAttributes(attr);            }        }



imageDialog为我们定义的对话框,在imageDialog.show()后面加这一段代码,可以实现从底部弹窗,并且占据整个屏幕宽度的对话框,因为我发现dialog 默认的样式@android:style/Theme.Dialog 对应的style 有pading属性,所以
win.getDecorView().setPadding(0, 0, 0, 0); 就能够水平占满了在此记录之,以备重用。

参考帖子http://bbs.csdn.net/topics/390175091/

2 0