dialog 设置宽高的四种方式 设置宽高无效问题

- xml布局指定layout宽高,dialog.setContentView

- dialog Java代码设置宽高的三种方式

   1、 dialog.getWindow().getDecorView().setMinimumWidth( DensityUtils.dip2px(context, 480));
       dialog.getWindow().getDecorView().setPadding(0,0,0,0);

   2、 dialog.getWindow().setLayout(DensityUtils.dip2px(context, 480), LinearLayout.LayoutParams.WRAP_CONTENT);
   
   3WindowManager.LayoutParams params = dialog.getWindow().getAttributes();
       params.width = DensityUtils.dip2px(context, 480);
       dialog.getWindow().setAttributes(params);

- 设置宽高无效问题处理

  1. 查看布局边界
> adb shell
> su
> setprop debug.layout 1
  1. AS查看进程窗口布局 右下角 Layout Inspector

在这里插入图片描述
设定Dialog宽高为何需要在Dialog.show()之后才有效

Dialog源码解析

猜你喜欢

转载自blog.csdn.net/qq_44256828/article/details/129800468