自定义对话框大小以匹配 Theme.Holo.Light.Dialog [英] Custom Dialog size to match Theme.Holo.Light.Dialog

查看:23
本文介绍了自定义对话框大小以匹配 Theme.Holo.Light.Dialog的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个 Activity 的主题设置为 Theme.Holo.Light.Dialog,它会很好地扩展.它会在纵向模式下几乎完全填满手机的屏幕,但在横向模式下它不会过度拉伸.例如,在 Google 的这张图片中,您可以看到对话框没有填满整个屏幕.

If I have an Activity that has it's theme set to Theme.Holo.Light.Dialog, it will scale great. It will fill the screen on phones in portrait mode almost entirely but in landscape mode it won't stretch unreasonably long. For example, in this picture from Google, you can see the dialog not filling the whole screen.

它不会折叠以匹配标题的宽度,就像如果您通过扩展 Dialog 类的类来构建自己的 Dialog 会发生的情况一样.

It won't either collapse to match the width of the title like what will happen if you have your own Dialog build by having a class that extends the Dialog class.

这就是我的布局会发生的事情.

This is what will happen with my layout.

我需要将哪些属性应用于 LinearLayout 以使其缩放更漂亮?

What properties do I need to apply to the LinearLayout to make it scale pretty?

推荐答案

您可以使用 Theme.Holo.Light.Dialog.MinWidth 来正确调整布局的大小.

You can use Theme.Holo.Light.Dialog.MinWidth for sizing your layout properly.

来自文档:

public static final int Theme_Holo_Light_Dialog_MinWidth

public static final int Theme_Holo_Light_Dialog_MinWidth

Theme.Holo.Light.Dialog 的变体,它有一个很好的最小宽度常规对话.

Variant of Theme.Holo.Light.Dialog that has a nice minimum width for a regular dialog.

使用它的方法是将 ContextThemeWrapper 代替 Context(使用它)传递给您的自定义 Dialog 的构造函数:

The way to use this would be through passing a ContextThemeWrapper in place of Context (using this) to your custom Dialog's constructor:

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:

@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:

@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%.

As it seems, the dialog's width in the picture you posted is around 65%. In the portrait mode, it would be 95%.

老实说,纵向模式下的宽度看起来不像 95%,但比以前好多了:):

Honestly, the width doesn't look like 95 % in portrait mode, but it's better than before :):

这篇关于自定义对话框大小以匹配 Theme.Holo.Light.Dialog的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆