我正在使用 Android SDK 制作游戏。一路上,我需要像任何其他游戏一样显示弹出窗口/对话框,用户可以升级或其他什么。我遇到的问题是对话框的大小。我正在使用RelativeLayout,并使用“wrap_content”将背景设置为图像。
问题是对话框采用内部视图的大小(或 Android 设置的默认对话框最小大小,以较大者为准)而不是背景图像。如果我使用 fill_parent 那么它会拉伸它。我花了几个小时旋转我的时间,但我似乎找不到一种有效的方法来使窗口的大小与背景图像的大小相匹配
有什么建议么?这是一个非常常见的用例,一定有办法!
谢谢
这是一些布局内容
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@drawable/popup"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageButton
android:id="@+id/ibCloseDialog"
android:background="@null"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/close" />
<Button
android:id="@+id/b1"
android:background="@drawable/blue_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@+id/b2"
android:text="b1" />
<Button
android:id="@+id/b2"
android:background="@drawable/blue_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="b2" />
<Button
android:id="@+id/b3"
android:background="@drawable/blue_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/b2"
android:text="b2" />
</RelativeLayout>
我曾经遇到过全屏显示对话框的问题。我使用自定义样式来删除对话框的默认样式(大小/边距/填充)。因此,也许您可以使用它来包装您的内容,同时忽略默认值。所以请尝试以下操作:
1) 在 styles.xml 中添加自定义对话框主题:
<style name="YourDialogTheme" parent="android:Theme.Dialog">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:windowBackground">@null</item>
<item name="android:windowNoTitle">false</item>
</style>
我认为高度、宽度和背景是这里的重要方面。也许你必须玩弄价值观。
2) 使用以下代码片段创建对话框:
Dialog dialog = new Dialog(context, R.style.YourDialogTheme)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)