【发布时间】:2015-08-24 14:08:36
【问题描述】:
我正在使用 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>
【问题讨论】:
-
一定有人遇到过这种情况
-
尝试使用
MATCH_PARENT -
看看这个答案,它可能会对你有所帮助。 stackoverflow.com/a/6631310/2071847
-
@holpducki match_parent 和 fill_parent 是一样的。一样的,新的名字
-
@amitfarag 哦!好久没碰
Android应用了