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

2023-09-07 14:20:09 作者:因为我的勇气

我使用的是Android SDK中进行游戏。一路上,我需要显示弹出/对话框,像任何其他游戏中有用户可以升级或什么的。我的问题是对话框的大小。我使用的RelativeLayout,我设置背景图片我有WRAP_CONTENT。

该对话框正在内的意见(或默认对话框最小尺寸由Android,取其大集)不是背景图像的大小问题。如果我使用FILL_PARENT那么它延伸它。我花了几个小时,我的旋转,而我似乎无法找到该窗口的大小,背景图像的尺寸相匹配的有效途径。

有什么建议?这是一个很常见的情况,并且必须有办法!谢谢

下面是一些版面内容的

 < RelativeLayout的    的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android    机器人:背景=@绘制/弹出    机器人:layout_width =WRAP_CONTENT    机器人:layout_height =WRAP_CONTENT>    <的ImageButton        机器人:ID =@ + ID / ibClos​​eDialog        机器人:背景=@空        机器人:layout_width =WRAP_CONTENT        机器人:layout_height =WRAP_CONTENT        机器人:SRC =@绘制/关闭/> <按钮        机器人:ID =@ + ID / B1        机器人:背景=@绘制/ blue_button        机器人:layout_width =WRAP_CONTENT        机器人:layout_height =WRAP_CONTENT        机器人:layout_toLeftOf =@ + ID / B2        机器人:文字=B1/>    <按钮        机器人:ID =@ + ID / B2        机器人:背景=@绘制/ blue_button        机器人:layout_width =WRAP_CONTENT        机器人:layout_height =WRAP_CONTENT        机器人:layout_centerHorizo​​ntal =真        机器人:文字=B2/>    <按钮        机器人:ID =@ + ID / B3        机器人:背景=@绘制/ blue_button        机器人:layout_width =WRAP_CONTENT        机器人:layout_height =WRAP_CONTENT        机器人:layout_toRightOf =@ + ID / B2        机器人:文字=B2/>< / RelativeLayout的> 

解决方案

我曾经面临全屏显示一个对话框一个问题。我用了一个自定义样式删除对话框默认样式(尺寸/保证金/填充)。因此,也许你可以使用这个而忽略默认值来包装你的内容。所以,请尝试以下方法:

1)在你的styles.xml添加自定义对话框主题:

 <样式名称=YourDialogTheme父=机器人:Theme.Dialog>    <项目名称=机器人:layout_width>&WRAP_CONTENT LT; /项目>    <项目名称=机器人:layout_height>&WRAP_CONTENT LT; /项目>    <项目名称=机器人:windowBackground> @空< /项目>    <项目名称=机器人:windowNoTitle>假LT; /项目>< /风格> 
对话框图片

我认为,高度,宽度和背景是这里的重要方面。也许你的价值观玩了。

2)使用这个片段创建对话框:

 对话对话框=新的对话框(背景下,R.style.YourDialogTheme) 

I am using the Android SDK to make a game. Along the way, I need to display popup/dialog like any other game there user can upgrade or whatever. The problem I have is with the size of the dialog. I am using RelativeLayout and I am setting the background to the image I have with "wrap_content".

The problem that the dialog is taking the size of the views inside (or the default dialog min size set by Android, whichever is bigger) NOT the background image. If I use fill_parent then it stretches it. I spent hours and hours spinning my while and I can't seem to find an efficient way in which the size of the window matches the size of the background image

Any suggestions? This is a very common use case and there must be way! Thanks

Here is some of the layout content

<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>

解决方案

I once faced a problem to display a Dialog in fullscreen. I used a custom style to remove the dialogs default styling (size / margin / padding). So maybe you could use this to wrap your content while ignoring the defaults. So please try the following:

1) Add a custom Dialog theme in your 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>

I think that height, width and background are the important aspects here. Maybe you have to play with the values.

2) Create your Dialog by using this snippet:

Dialog dialog = new Dialog(context, R.style.YourDialogTheme)

 
精彩推荐
图片推荐