简体   繁体   English

对话框占用整个屏幕宽度

[英]Dialog is taking the whole screen width

I have made a custom Dialog 我做了一个自定义对话框

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:id="@+id/dialog_root"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="@dimen/dialog_text_padding"
    android:paddingRight="@dimen/dialog_text_padding"
    android:paddingTop="@dimen/dialog_text_padding">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/dialog_heading"
        tools:text="Permissions"
        android:textStyle="bold"
        android:textColor="@color/brand_color"
        android:textSize="22sp"
        />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/dialog_text"
        android:clickable="true"
        android:layout_marginTop="@dimen/padding_large"
        android:textSize="18sp"
        tools:text="This app determines your phone location and shares it with Google to server personalized alters for you. This allows for a better app pferformance"/>





    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingBottom="24dp"
        android:id="@+id/okCancelView"
        android:paddingTop="@dimen/dialog_text_padding"
        android:paddingLeft="@dimen/dialog_text_padding"

       >

        <TextView
            android:layout_width="wrap_content"
            android:layout_toLeftOf="@+id/dialog_cancel"
            android:layout_marginRight="@dimen/dialog_text_padding"
            android:gravity="center"
            android:layout_height="wrap_content"
             android:paddingTop="10dp"
            android:paddingBottom="10dp"
            android:paddingLeft="20dp"
            android:paddingRight="20dp"
            tools:text="OK"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            tools:text="CANCEL"
            android:padding="10dp"
            android:layout_alignParentRight="true"
            android:textColor="@color/dialog_heading"
            android:gravity="center"/>

        </RelativeLayout>

</LinearLayout>

I am showing it with simple 我用简单的方式展示

Dialog d=new Dialog(this);
d.setContentView(R.layout.custom_dialog);
d.show();

But my dialog is taking full width of the screen( image attached). 但是我的对话框占用了整个屏幕的宽度(已附加图片)。 Why is there no space between screen and dialog? 为什么屏幕和对话框之间没有空间?

在此处输入图片说明

Display display = ((Activity) ctx).getWindowManager()
                    .getDefaultDisplay();
            Point size = new Point();
            display.getSize(size);
            int width = size.x;
            alert_dialog.getWindow().setLayout((int) (width * .89),
                    LayoutParams.WRAP_CONTENT);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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