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

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

问题描述

如果我有,有一个活动是主题设置为 Theme.Holo.Light.Dialog ,将规模巨大。这将填补在手机屏幕纵向模式几乎完全,但在横向模式下也不会伸展过长。例如,在这张照片从谷歌,你可以看到对话框不填充整个屏幕。

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.

我需要什么样的属性应用到的LinearLayout,使其规模pretty的?

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.

从文档:

公共静态最终诠释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到位语境(使用本)添加到您的自定义对话框的构造方式:

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:扪/ 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:扪/ 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天全站免登陆