Mik*_*koP 10 android dialog android-layout android-xml android-dialog
如果我有一个将其主题设置为的活动Theme.Holo.Light.Dialog,它将扩展得很好.它几乎完全以纵向模式填充在手机屏幕上,但在横向模式下,它不会长时间不合理地伸展.例如,在Google的这张图片中,您可以看到对话框没有填满整个屏幕.

它不会崩溃以匹配标题的宽度,如果你有一个扩展Dialog类的类有你自己的Dialog构建会发生什么.
这是我的布局会发生的事情.

我需要将哪些属性应用于LinearLayout以使其扩展得相当漂亮?
Vik*_*ram 27
您可以使用Theme.Holo.Light.Dialog.MinWidth正确调整布局大小.
从文档:
public static final int Theme_Holo_Light_Dialog_MinWidth
Theme.Holo.Light.Dialog的变体,具有常规对话框的最小宽度.
使用它的方法是通过将ContextThemeWrapper代替Context(使用它)传递给自定义Dialog的构造函数:
YourCustomDialog cDialog = new YourCustomDialog(
new ContextThemeWrapper(this,
android.R.style.Theme_Holo_Light_Dialog_MinWidth));
Run Code Online (Sandbox Code Playgroud)
这是如何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>
Run Code Online (Sandbox Code Playgroud)
来自dimens.xml:
@android:扪/ 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>
Run Code Online (Sandbox Code Playgroud)
@android:扪/ 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>
Run Code Online (Sandbox Code Playgroud)
看起来,您发布的图片中对话框的宽度约为65%.在肖像模式中,它将是95%.
老实说,在纵向模式下宽度看起来不像95%,但它比以前更好:):

| 归档时间: |
|
| 查看次数: |
15958 次 |
| 最近记录: |