您可以使用Theme.Holo.Light.Dialog.MinWidth 正确调整布局大小。
来自文档:
public static final int Theme_Holo_Light_Dialog_MinWidth
Theme.Holo.Light.Dialog 的变体,具有很好的最小宽度
常规对话。
使用 this 的方法是通过将 ContextThemeWrapper 代替 Context(使用 this)传递给自定义 Dialog 的构造函数:
YourCustomDialog cDialog = new YourCustomDialog(
new ContextThemeWrapper(this,
android.R.style.Theme_Holo_Light_Dialog_MinWidth));
Theme.Holo.Light.Dialog.MinWidth 是这样定义的:
<style name="Theme.Holo.Light.Dialog.MinWidth">
<item name="android:windowMinWidthMajor">@android:dimen/dialog_min_width_major</item>
<item name="android:windowMinWidthMinor">@android:dimen/dialog_min_width_minor</item>
</style>
来自dimens.xml:
@android:dimen/dialog_min_width_major:
<!-- The platform's desired minimum size for a dialog's width when it
is along the major axis (that is the screen is landscape). This may
be either a fraction or a dimension. -->
<item type="dimen" name="dialog_min_width_major">65%</item>
@android:dimen/dialog_min_width_minor:
<!-- The platform's desired minimum size for a dialog's width when it
is along the minor axis (that is the screen is portrait). This may
be either a fraction or a dimension. -->
<item type="dimen" name="dialog_min_width_minor">95%</item>
看起来,您发布的图片中对话框的宽度约为 65%。在纵向模式下,它会是 95%。
老实说,纵向模式下的宽度看起来不像 95 %,但比以前好多了:):