对话框大小与背景图像不匹配

Sna*_*ake 11 android android-dialog

我正在使用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>
Run Code Online (Sandbox Code Playgroud)

Jor*_*ego 0

您是否在RelativeLayout中使用属性“android:background”?如果是这种情况,您可以尝试这样做:

 <RelativeLayout
        .
        .
        .
        >
        <ImageView
            android:layout_width="MATCH_PARENT"
            android:layout_height="MATCH_PARENT"
            android:scaleType="fitXY"
            android:adjustViewBounds="true" 
            android:src="@drawable/yourDrawable" />    
    </RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
  1. 将 ImageView 放入相对布局中。
  2. 删除RelativeLayout的背景图片
  3. 将 ImageView 的 src 设置为背景图片

还:

  • 制作正确大小的背景图像并将它们保存在不同的可绘制文件夹中。
  • 不使用常量,而是以 dp 为单位指定视图的大小