Наложение изображения поверх пользовательского AlertDialog в Android Studio - PullRequest
0 голосов
/ 18 апреля 2020

Я пытаюсь наложить изображение поверх настраиваемого диалогового окна предупреждения, как . Я попытался установить layout_marginTop для imageView с отрицательным значением, но изображение кажется обрезанным.

Вот как выглядит мой вывод .

Это мой код в Java

AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
View view = getLayoutInflater().inflate(R.layout.dialog_error, null);

ivError = view.findViewById(R.id.ivError);
lblError = view.findViewById(R.id.lblError);
tvError = view.findViewById(R.id.tvError);

builder.setView(view);
AlertDialog dialog = builder.create();
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialog.show();

, а это мой код в XML.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/round_corner_template"
android:orientation="vertical">

<ImageView
    android:id="@+id/ivError"
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:layout_centerHorizontal="true"
    android:layout_alignParentTop="true"
    android:layout_marginTop="-60dp"
    android:src="@drawable/pic_error" />

<TextView
    android:id="@+id/lblError"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/ivError"
    android:fontFamily="sans-serif-black"
    android:gravity="center"
    android:text="Error Text"
    android:textSize="15sp"
    android:textStyle="bold" />

<TextView
    android:id="@+id/tvError"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/lblError"
    android:layout_marginTop="10dp"
    android:gravity="center"
    android:text="Error Text"
    android:textSize="12sp" />

</RelativeLayout>

1 Ответ

0 голосов
/ 18 апреля 2020

Пожалуйста, измените ваш xml вот так и посмотрите, как это должно выглядеть

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/round_corner_template"
    android:orientation="vertical">

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="50dp"
        android:orientation="vertical" >
    </LinearLayout>

    <ImageView
        android:id="@+id/ivError"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:src="@drawable/pic_error" />

    <TextView
        android:id="@+id/lblError"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/ivError"
        android:fontFamily="sans-serif-black"
        android:gravity="center"
        android:text="Error Text"
        android:textSize="15sp"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/tvError"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/lblError"
        android:layout_marginTop="10dp"
        android:gravity="center"
        android:text="Error Text"
        android:textSize="12sp" />

</RelativeLayout>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...