无法在自定义对话框视图中删除 Android 布局文件末尾的白色 space

Unable to remove white space at the end of Android layout file in a custom dialog view

我正在尝试在 activity 中加载对话框的自定义视图。我想删除对话框右侧的白色 space 。

我的activity

public class MyActivity extends AppCompatActivity {


  @Override
  protected void onCreate(final Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.my_activity);
     showClippingCoupon();
  }
}

我的对话代码

void showClippingCoupon()
{
    LayoutInflater layoutInflater = getLayoutInflater();
    View toastView = layoutInflater.inflate(R.layout.clipping_coupon_toast, null);

    AlertDialog.Builder builder = new AlertDialog.Builder(this).setView(toastView);
    AlertDialog dialog = builder.create();
    dialog.setCanceledOnTouchOutside(true);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    TextView couponCodeText = (TextView) toastView.findViewById(R.id.coupon_code_text);

    couponCodeText.setText("Y34UIDEFDK");
    ImageView closeButtonImageView = (ImageView) toastView.findViewById(R.id.coupon_close);
    if (closeButtonImageView != null)
    {
      closeButtonImageView.setOnClickListener(new OnClickListener()
      {
        @Override
        public void onClick(View v)
        {
          dialog.dismiss();
        }
      });
    }

    dialog.show();
}

我的activity布局

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/layout">
</FrameLayout>

我正在尝试在 activity 中加载自定义对话框视图。这就是它应该的样子。

但这就是我得到的

这是它在预览中的样子。

这是对话框的布局。

        <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:background="@color/coupon_text_color_v2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <ImageView
        android:layout_width="wrap_content"
        android:id="@+id/coupon_clip_success_icon"
        android:src="@drawable/ic_check_circle_green"
        app:layout_constraintStart_toStartOf="parent"
        android:contentDescription="@android:string/ok"
        app:layout_constraintTop_toTopOf="parent"
        android:layout_margin="16dp"
        android:layout_toStartOf="@+id/coupon_body"
        android:layout_height="wrap_content" />
    <RelativeLayout
        android:layout_width="wrap_content"
        android:id="@+id/coupon_body"
        android:focusable="true"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintStart_toEndOf="@+id/coupon_clip_success_icon"
        android:layout_height="wrap_content">
        <TextView
            android:layout_width="wrap_content"
            android:id="@+id/coupon_copied_text"
            android:layout_gravity="center_horizontal"
            android:layout_marginBottom="8dp"
            android:layout_marginTop="16dp"
            android:layout_marginStart="16dp"
            android:layout_marginEnd="48dp"
            android:text="@string/coupon_code_copied"
            android:textAppearance="@style/Small"
            android:layout_height="wrap_content" />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/coupon_code_text"
            android:layout_below="@+id/coupon_copied_text"
            android:layout_marginStart="16dp"
            android:layout_marginBottom="16dp"
            android:text="Test"
            android:textAppearance="@style/Small.Bold"
            />

    </RelativeLayout>
    <ImageView
        android:id="@+id/coupon_close"
        android:src="@drawable/ic_clear"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        app:layout_constraintStart_toEndOf="@+id/coupon_body"
        android:layout_marginEnd="8dp"
        app:layout_constraintTop_toTopOf="parent"
        android:layout_gravity="top|right"
        android:contentDescription="@string/close" />

</androidx.constraintlayout.widget.ConstraintLayout>

我应该怎么做才能删除对话框右侧的白色 space?

ConstraintLayout :- width : match_parent and replace your Imageview 
 <ImageView
        android:id="@+id/coupon_close"
        android:src="@drawable/ic_clear"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:layout_marginEnd="8dp"
        android:contentDescription="@string/close" />