使用图像将对话框拉伸到全高

时间:2015-11-01 12:49:25

标签: android dialog

我想使用图像作为对话框的背景,但它使对话框与屏幕一样高。我检查了thisthis以及this个答案,他们都提出了同样的建议,但这对我不起作用。

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

哦,我指定布局的宽度为

DisplayMetrics metrics = getResources().getDisplayMetrics();
int width = metrics.widthPixels;
dialogsignin.getWindow().setLayout((9 * width) / 10, LinearLayout.LayoutParams.WRAP_CONTENT);

0 个答案:

没有答案