我正在使用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
。 - alexandreferris