Dialog设置大小为什么需要在setContentView方法之后?
诊断程序设置大小实际上也由WindowManager.LayoutParams的width,height属性控制
但是,从与诊断程序内部相关的窗口(phone window )的窗口管理器. layout params的width来看,heigh的默认值都是MATCH_PARENT,但setcontent
首先查看诊断程序的默认相关窗口
dialog(@nonnullcontextcontext,@StyleRes int themeResId,booleancreatecontextthemewrapper )//.省略final window=new phonhone
窗口窗口管理器. layout params的默认结构(width,height均为MATCH_PARENT ) ) ) ) ) ) ) ) ) )。
接下来,我们来看看为什么setContentView发生了变化
@ overridepublicvoidsetcontentview (intlayoutresid )//note : feature _ content _ transitionsmaybesetintheprocessoutofininnnnnnnentview whenthemeattributesandthelikearecrystalized.donotcheckthefeature//beforethishappens.//初次执行此处为空,因此条件为if (mcontentpatpate ) has feature (feature _ content _ transitions ) { mcontent parent.remove all views }; } if (has feature (feature _ content _ transitions ) ) finalscenenewscene=scene.getsceneforlayout ) mcontentparent,tiout } else { mlayoutinflater.inflate (layout resid,mContentParent ); } mcontent parent.requestapplyinsets (; final Callback cb=getCallback (; if(CB!=空! isDestroyed () ) { cb.onContentChanged; } mcontentparentexplicitlyset=true; 继续跟进安装解码器方法
其中,generateDecor ) )方法创建mDecor中的方法与我们的大小无关。 重点关注generateLayout方法
在这里,我们看到大小更改为WRAP_CONTENT,但存在mIsFloating是否为true的限制
接下来,我们正在验证mIsFloating的值是如何来的
在上图中,我们看到mIsFloating解析窗口样式而来。 那我们来跟进一下吧
分析R.styleable.Window属性
查看自己的诊断样式时,发现了windowIsFloating的默认值true
因此,如果使用的是诊断程序,并且样式中包含itemname=' Android 3360 windowisfloating ' true/item,则在setContentView方法之后显示width,height专业程序
分析源代码后,必须在setContentView方法之后才能修改诊断程序大小