简体   繁体   中英

Android custom dialog not fill the entire dialog layout

I build a custom dialog to pop up an image with close button like this:

结果

As you can see the dialog is not fitting the dialog layout and there's this white borer on the top and on the right, so how can i get rid the white border thing and make my custom dialog fit?

<?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>
getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));

在Dialog类中使用上述代码来使Dialog TransParent

Remove margin Top and right on LinearLayout:

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

To make the Dialog bigger, you can set those parameters to 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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM