// 是否是dialog样式的界面,android:windowIsFloating属性
mIsFloating = a.getBoolean(com.android.internal.R.styleable.Window_windowIsFloating, false);
int flagToUpdate = (FLAG_LAYOUT_IN_SCREEN|FLAG_LAYOUT_INSET_DECOR) & (~getForcedWindowFlags());
// 如果是dialog样式,则设置当前的WindowManager.LayoutParams的width和height值,代表该界面的大小由布局文件大小指定。
// 因为默认的WindowManager.LayoutParams的width和height是MATCH_PARENT,即与屏幕大小一致。
if (mIsFloating) {
setLayout(WRAP_CONTENT, WRAP_CONTENT);
setFlags(0, flagsToUpdate);
} else {
setFlags(FLAG_LAYOUT_IN_SCREEN|FLAG_LAYOUT_INSET_DECOR, flagsToUpdate);
}
public void setLayout(int width, int height) {
final WindowManager.LayoutParams attrs = getAttributes();
attrs.width = width;
attrs.height = height;
dispatchWindowAttrbutesChanged(attrs);
}
下面再详细点:
windowIsFloating属性设置为false, 默认将Window设置成全屏大小,设置为true,则window大小为wrap_content。
如果dialog布局大小不变,而window大小为全屏,且gravity没有设置为center,那么可能导致dailog在左上角而不是中间,而且window大小全屏时会导致touchoutside失效。