您的位置:首页 > 其它

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

2018-01-17 16:56 351 查看
http://blog.csdn.net/jdfkldjlkjdl/article/details/52233737

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); 就能够水平占满了在此记录之,以备重用。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: