Reputation: 43883
In my android project, when I set a background for a dialog in the xml code (the dialog uses a xml file for the layout), the dialog window size increases to fit the background image in it.
How can I set it so that the window size does not increase. It just ignores the background part that won't appear in the dialog. I guess the anchor of the image can be the center or the top left, doesn't matter.
Does anyone know how to do this?
Thanks.
Upvotes: 4
Views: 2568
Reputation: 910
I found the solution, see here: Scale down (or crop) dialog background in Android
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android">
<ImageView
android:src="@drawable/back_dialog"
android:scaleType="fitXY"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_alignTop="@+id/dialog_layout_main"
android:layout_alignBottom="@id/dialog_layout_main"
android:layout_alignLeft="@id/dialog_layout_main"
android:layout_alignRight="@id/dialog_layout_main" />
<LinearLayout
android:id="@+id/dialog_layout_main"
android:layout_width="match_parent"
android:layout_height="wrap_content">
.........
</LinearLayout>
</RelativeLayout>
Upvotes: 1
Reputation: 3745
Either set layout width and height for the parent layout static or do it for the ImageView. Setting match_parent, wrap_content or fill_parent(deprecated) will make dialog to expand to ImageView.
Upvotes: 0