【发布时间】:2018-02-17 10:13:49
【问题描述】:
我打算用自定义布局显示Dialog:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:background="#ffffff"
android:layout_height="match_parent"
android:orientation="vertical" >
<WebView
android:id="@+id/webv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginRight="@dimen/lef_margin"
android:layout_marginTop="@dimen/lef_margin"
android:background="#ffffff"
android:fitsSystemWindows="true" />
<ImageView
android:id="@+id/imgsocialauthclose"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_gravity="right|top"
android:background="@drawable/closexml" />
</FrameLayout>
现在,如果我通过Dialog.setContentView() 将此布局设置为对话框,我会得到如下所示的内容(请注意,相关对话框是中间带有十字按钮的白色框,而不是一个在后台包含所有社交媒体选项):
现在,如果我要在 setContentView() 调用之外编写这一附加行,我会得到一个扩展到覆盖父视图的对话框:
dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
如果您观察布局,您会注意到 MATCH_PARENT 约束已被声明。那么,为什么我需要做这个额外的行,或者,
为什么对话框默认不正确遵守 MATCH_PARENT 约束?
【问题讨论】: