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

http://blog.csdn.net/jdfkldjlkjdl/article/details/52233737


  1. imageDialog.show();  
  2. Window window = imageDialog.getWindow();  
  3. if (imageDialog != null && window != null) {  
  4.     window.getDecorView().setPadding(0000);  
  5.     WindowManager.LayoutParams attr = window.getAttributes();  
  6.     if (attr != null) {  
  7.         attr.height = ViewGroup.LayoutParams.WRAP_CONTENT;  
  8.         attr.width = ViewGroup.LayoutParams.MATCH_PARENT;  
  9.         attr.gravity = Gravity.BOTTOM;//设置dialog 在布局中的位置  
  10.   
  11.         window.setAttributes(attr);  
  12.     }  
  13. }  



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


猜你喜欢

转载自blog.csdn.net/wangpanbaoding/article/details/79087428