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

时间:2016-04-29 10:18:38

标签: java android xml layout dialog

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

result

正如您所看到的那样,对话框不适合对话框布局,并且顶部和右侧有白色镗孔,那么如何摆脱白色边框并使我的自定义对话框合适? / p>

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

3 个答案:

答案 0 :(得分:1)

getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));

在Dialog类中使用Above Code来制作Dialog TransParent

答案 1 :(得分:0)

在LinearLayout上删除上边和右上边距:

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

答案 2 :(得分:0)

要使Dialog更大,可以将这些参数设置为MATCH_PARENT。

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();