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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With