Java Android自定义对话框未填充整个对话框布局

Java Android自定义对话框未填充整个对话框布局,java,android,xml,layout,dialog,Java,Android,Xml,Layout,Dialog,我构建了一个自定义对话框,用关闭按钮弹出一个图像,如下所示: 正如您所看到的,对话框不适合对话框布局,在顶部和右侧有一个白色的钻孔器,那么我如何摆脱白色边框的东西,使我的自定义对话框适合 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pa

我构建了一个自定义对话框,用关闭按钮弹出一个图像,如下所示:

正如您所看到的,对话框不适合对话框布局,在顶部和右侧有一个白色的钻孔器,那么我如何摆脱白色边框的东西,使我的自定义对话框适合

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center_vertical"
    android:gravity="center"
    android:orientation="vertical" >

<FrameLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true" >

    <LinearLayout
        android:id="@+id/linearMain"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="5dp"
        android:layout_marginTop="10dp"
        android:gravity="center"
        android:orientation="vertical"
        android:paddingBottom="-50dp" >
        <ImageView
            android:id="@+id/imgMain"
            android:layout_width="300dp"
            android:layout_height="350dp"
            android:gravity="center"
            android:background="@drawable/eairh_dialog"
            />

        <!---add your views here-->
    </LinearLayout>
    <ImageView
        android:id="@+id/imgClose"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="top|right"
        android:clickable="true"
        android:src="@drawable/close_button" />
</FrameLayout>

</LinearLayout>


在Dialog类中使用上述代码使对话框透明

删除LinearLayout顶部和右侧的边距:

android:layout_marginRight="5dp"
android:layout_marginTop="10dp"

要使对话框更大,可以将这些参数设置为与父项匹配

int screenWidth = 0, screenHeight = 0 ;
 Display display = thid.getWindowManager().getDefaultDisplay();
        screenWidth = display.getWidth();
        screenHeight = display.getHeight();


        Dialog dialog = new Dialog(getActivity(), android.R.style.Theme_DeviceDefault);
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        dialog.setContentView(R.layout.cart_empty);

           WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
        lp.copyFrom(dialog.getWindow().getAttributes());
        lp.width = screenWidth;
        lp.height = screenHeight;
        dialog.getWindow().setAttributes(lp);
        dialog.show();

移除顶部和右侧的边距..从线性布局中移除android:layout_marginRight=“5dp”android:layout_marginTop=“10dp”它正在工作,但关闭图像现在位于主图像中,我希望关闭图像与第一张图片一样
int screenWidth = 0, screenHeight = 0 ;
 Display display = thid.getWindowManager().getDefaultDisplay();
        screenWidth = display.getWidth();
        screenHeight = display.getHeight();


        Dialog dialog = new Dialog(getActivity(), android.R.style.Theme_DeviceDefault);
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        dialog.setContentView(R.layout.cart_empty);

           WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
        lp.copyFrom(dialog.getWindow().getAttributes());
        lp.width = screenWidth;
        lp.height = screenHeight;
        dialog.getWindow().setAttributes(lp);
        dialog.show();