0

I want to use an image as my dialog's background but it makes the dialog as high as the screen. I checked this and this and this answers and they all suggest the same but it's not working for me.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:clipToPadding="true"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <ImageView
        android:src="@drawable/wood"
        android:clipToPadding="true"
        android:scaleType="fitXY"
        android:adjustViewBounds="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        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"
    android:clipToPadding="true"
    android:orientation="vertical"
    android:padding="20dp"
    android:background="@drawable/wood">


    <TextView
        android:id="@+id/tv_1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:gravity="center_horizontal"
        android:text="You're getting better!"
        android:textSize="24sp"
        android:textColor="#486783"/>

    <TextView
        android:id="@+id/tv_2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:gravity="center_horizontal"
        android:layout_marginTop="10dp"
        android:visibility="gone"
        android:text="Do you know what would be even better?"
        android:textSize="22sp"
        android:textColor="#486783"/>

    <TextView
        android:id="@+id/tv_3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:gravity="center_horizontal"
        android:layout_marginTop="20dp"
        android:text="Sign in with Google+ to save your progress in the cloud and compare your results against other players!"
        android:textSize="20sp"
        android:textColor="#486783"/>

    <Button
        android:id="@+id/btn_signin"
        android:background="@drawable/google_button_selector"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="20dp"
        android:gravity="center"
        android:layout_gravity="center_horizontal"
        android:text="Sign in with Google+"
        android:textColor="#FFFFFF"
        android:textSize="18sp" />

</LinearLayout>

    </RelativeLayout>

Oh, and I specify the width of the layout as

DisplayMetrics metrics = getResources().getDisplayMetrics();
int width = metrics.widthPixels;
dialogsignin.getWindow().setLayout((9 * width) / 10, LinearLayout.LayoutParams.WRAP_CONTENT);
Cœur
  • 37,241
  • 25
  • 195
  • 267
erdomester
  • 11,789
  • 32
  • 132
  • 234
  • How am I supposed to use layout_weight in a RelativeLayout? Btw the link is wrong. – erdomester Nov 01 '15 at 13:07
  • I made the image smaller and that solved it. I hate playing with different sizes as who knows how will they look like on different screen sizes. – erdomester Nov 01 '15 at 13:15

0 Answers0