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

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

问题描述

如果我有一个活动的主题设置为 Theme.Holo.Light.Dialog ,它将扩大很大。它将几乎完全以纵向模式在手机上填充屏幕,但在风景模式下,它不会拉长不合时宜。例如,在Google的这张照片中,您可以看到对话框未填写整个屏幕。





它不会崩溃以匹配标题的宽度,如果你有通过拥有扩展Dialog类的类,您自己的Dialog构建。



这是我的布局会发生什么。





我需要什么属性来应用于LinearLayout以使其变得漂亮?

解决方案

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



从文档中:


public static final int Theme_Holo_Light_Dialog_MinWidth



Theme.Holo.Light.Dialog的变体,对于
常规对话框,具有不错的最小宽度。


使用它的方法是通过将ContextThemeWrapper代替到您的自定义Dialog的构造函数的Context(使用此):

  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>

dimensions.xml



@android:dimen / dialog_min_width_major:

 <! - 当
沿着主轴(即屏幕是横向)时,对话框宽度的所需最小尺寸。这可能是
是分数或维数。 - >
< item type =dimenname =dialog_min_width_major> 65%< / item>

@android:dimen / dialog_min_width_minor:

 <! - 当
沿着短轴(即屏幕为纵向)时,平台所需的对话框宽度的最小尺寸。这可能是
是分数或维数。 - >
< item type =dimenname =dialog_min_width_minor> 95%< / item>

看来,您发布的图片中的对话框的宽度大约为65%。在肖像模式下,这将是95%。



老实说,在纵向模式下,宽度看起来不像95%,但比以前更好:): / p>


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.

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.

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

解决方案

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

From the documentation:

public static final int Theme_Holo_Light_Dialog_MinWidth

Variant of Theme.Holo.Light.Dialog that has a nice minimum width for a regular 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));

This is how Theme.Holo.Light.Dialog.MinWidth is defined:

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

From 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>

As it seems, the dialog's width in the picture you posted is around 65%. In the portrait mode, it would be 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天全站免登陆