Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/205.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 我想要一个带有关闭按钮的自定义对话_Android - Fatal编程技术网

Android 我想要一个带有关闭按钮的自定义对话

Android 我想要一个带有关闭按钮的自定义对话,android,Android,我已经完成了编码,但问题是当我打开对话框时,关闭按钮只显示一半。它仅显示相对布局内部的关闭按钮部分。 外部部分尚未显示。我试了几个小时,但仍然没有得到解决方案。所以如果有人有想法,请帮助我。 提前谢谢! 下面是我的代码 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layo

我已经完成了编码,但问题是当我打开对话框时,关闭按钮只显示一半。它仅显示相对布局内部的关闭按钮部分。 外部部分尚未显示。我试了几个小时,但仍然没有得到解决方案。所以如果有人有想法,请帮助我。 提前谢谢! 下面是我的代码

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/transparent">
    <LinearLayout
        android:id="@+id/relativeLayout1"
        android:layout_width="255dp"
        android:layout_height="385dp"
        android:layout_centerInParent="true"
        android:background="@android:color/white"
        android:orientation="vertical" >
        <Button
            android:id="@+id/btn_From_Gallary"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="16dp"
            android:layout_marginRight="16dp"
            android:padding="20dp"
            android:layout_marginTop="60dp"
            android:layout_marginBottom="16dp"
            android:text="Choose From Gallary"
            android:background="@color/colorAccent"
            android:textColor="#ffffff"
            android:textSize="16sp" />
        <Button
            android:id="@+id/btn_Camera"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="16dp"
            android:layout_marginRight="16dp"
            android:layout_below="@+id/btn_From_Gallary"
            android:padding="20dp"
            android:text="Take a Picture"
            android:background="@color/colorAccent"
            android:textColor="#ffffff"
            android:textSize="16sp" />
        <Button
            android:id="@+id/btn_Send_Text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="16dp"
            android:layout_marginRight="16dp"
            android:layout_marginTop="20dp"
            android:layout_marginBottom="20dp"
            android:layout_below="@+id/btn_From_Gallary"
            android:padding="20dp"
            android:text="Text"
            android:background="@color/colorAccent"
            android:textColor="#ffffff"
            android:textSize="16sp" />
        <EditText
            android:id="@+id/edt_notification_text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp"
            android:layout_marginTop="20dp"
            android:visibility="gone"
            android:background="@drawable/edittext_border"
            android:gravity="top|left"
            android:inputType="textMultiLine"
            android:lines="5"
            android:maxLength="250"
            android:maxLines="3"
            android:padding="5dp"
            android:scrollbars="vertical" />
        <ImageView
            android:id="@+id/image"
            android:layout_width="150dp"
            android:layout_height="150dp"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp"
            android:layout_marginTop="20dp"
            android:gravity="top|left"
            android:visibility="gone"
            android:inputType="textMultiLine"
            android:lines="5"
            android:maxLength="250"
            android:maxLines="3"
            android:padding="5dp"
            android:scrollbars="vertical" />
        <Button
            android:id="@+id/btn_Send"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="16dp"
            android:visibility="gone"
            android:layout_marginRight="16dp"
            android:layout_marginTop="50dp"
            android:layout_marginBottom="20dp"
            android:layout_below="@+id/btn_From_Gallary"
            android:padding="20dp"
            android:text="Send"
            android:background="@color/colorAccent"
            android:textColor="#ffffff"
            android:textSize="16sp" />    
    </LinearLayout>
    <ImageView
        android:id="@+id/img_close"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignRight="@+id/relativeLayout1"
        android:layout_alignTop="@+id/relativeLayout1"
        android:layout_marginRight="-10dp"
        android:layout_marginTop="-10dp"
        android:src="@drawable/ic_cancel" /></RelativeLayout>

试试这个

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@android:color/transparent">

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginRight="30dp"
        android:layout_marginTop="57dp"
        android:background="@color/colorWhite"
        android:orientation="vertical">

        <Button
            android:id="@+id/btn_From_Gallary"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="16dp"
            android:layout_marginRight="16dp"
            android:padding="20dp"
            android:layout_marginTop="60dp"
            android:layout_marginBottom="16dp"
            android:text="Choose From Gallary"
            android:background="@color/colorAccent"
            android:textColor="#ffffff"
            android:textSize="16sp" />
        <Button
            android:id="@+id/btn_Camera"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="16dp"
            android:layout_marginRight="16dp"
            android:layout_below="@+id/btn_From_Gallary"
            android:padding="20dp"
            android:text="Take a Picture"
            android:background="@color/colorAccent"
            android:textColor="#ffffff"
            android:textSize="16sp" />
        <Button
            android:id="@+id/btn_Send_Text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="16dp"
            android:layout_marginRight="16dp"
            android:layout_marginTop="20dp"
            android:layout_marginBottom="20dp"
            android:layout_below="@+id/btn_From_Gallary"
            android:padding="20dp"
            android:text="Text"
            android:background="@color/colorAccent"
            android:textColor="#ffffff"
            android:textSize="16sp" />
        <EditText
            android:id="@+id/edt_notification_text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp"
            android:layout_marginTop="20dp"
            android:visibility="gone"
            android:background="@drawable/edittext_border"
            android:gravity="top|left"
            android:inputType="textMultiLine"
            android:lines="5"
            android:maxLength="250"
            android:maxLines="3"
            android:padding="5dp"
            android:scrollbars="vertical" />
        <ImageView
            android:id="@+id/image"
            android:layout_width="150dp"
            android:layout_height="150dp"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp"
            android:layout_marginTop="20dp"
            android:gravity="top|left"
            android:visibility="gone"
            android:inputType="textMultiLine"
            android:lines="5"
            android:maxLength="250"
            android:maxLines="3"
            android:padding="5dp"
            android:scrollbars="vertical" />
        <Button
            android:id="@+id/btn_Send"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="16dp"
            android:visibility="gone"
            android:layout_marginRight="16dp"
            android:layout_marginTop="50dp"
            android:layout_marginBottom="20dp"
            android:layout_below="@+id/btn_From_Gallary"
            android:padding="20dp"
            android:text="Send"
            android:background="@color/colorAccent"
            android:textColor="#ffffff"
            android:textSize="16sp" />



    </LinearLayout>

    <ImageView
        android:id="@+id/img_close"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_marginRight="-35dp"
        android:layout_marginTop="35dp"
        />

</RelativeLayout>

使用以下代码:

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/transparent">

    <LinearLayout
        android:id="@+id/relativeLayout1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:background="@android:color/white"
        android:orientation="vertical">

        <Button
            android:id="@+id/btn_From_Gallary"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="16dp"
            android:layout_marginLeft="16dp"
            android:layout_marginRight="16dp"
            android:layout_marginTop="60dp"
            android:background="@color/colorAccent"
            android:padding="20dp"
            android:text="Choose From Gallary"
            android:textColor="#ffffff"
            android:textSize="16sp" />

        <Button
            android:id="@+id/btn_Camera"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/btn_From_Gallary"
            android:layout_marginLeft="16dp"
            android:layout_marginRight="16dp"
            android:background="@color/colorAccent"
            android:padding="20dp"
            android:text="Take a Picture"
            android:textColor="#ffffff"
            android:textSize="16sp" />

        <Button
            android:id="@+id/btn_Send_Text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/btn_From_Gallary"
            android:layout_marginBottom="20dp"
            android:layout_marginLeft="16dp"
            android:layout_marginRight="16dp"
            android:layout_marginTop="20dp"
            android:background="@color/colorAccent"
            android:padding="20dp"
            android:text="Text"
            android:textColor="#ffffff"
            android:textSize="16sp" />

        <EditText
            android:id="@+id/edt_notification_text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp"
            android:layout_marginTop="20dp"
            android:gravity="top|left"
            android:inputType="textMultiLine"
            android:lines="5"
            android:maxLength="250"
            android:maxLines="3"
            android:padding="5dp"
            android:scrollbars="vertical"
            android:visibility="gone"
            android:background="@drawable/edittext_border" />

        <ImageView
            android:id="@+id/image"
            android:layout_width="150dp"
            android:layout_height="150dp"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp"
            android:layout_marginTop="20dp"
            android:gravity="top|left"
            android:inputType="textMultiLine"
            android:lines="5"
            android:maxLength="250"
            android:maxLines="3"
            android:padding="5dp"
            android:scrollbars="vertical"
            android:visibility="gone" />

        <Button
            android:id="@+id/btn_Send"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/btn_From_Gallary"
            android:layout_marginBottom="20dp"
            android:layout_marginLeft="16dp"
            android:layout_marginRight="16dp"
            android:layout_marginTop="50dp"
            android:background="@color/colorAccent"
            android:padding="20dp"
            android:text="Send"
            android:textColor="#ffffff"
            android:textSize="16sp"
            android:visibility="gone" />
    </LinearLayout>

    <ImageView
        android:id="@+id/img_close"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignEnd="@+id/relativeLayout1"
        android:layout_alignTop="@+id/relativeLayout1"
        android:src="@drawable/ic_cancel" />
</RelativeLayout>


对为什么这应该能解决问题进行某种解释是很好的。@Michael是的,我应该解释一下。这里是:@DeepPatel因为它是线性布局,所以在这种情况下,布局宽度和布局高度都应该是包裹内容。您在layout_marginRight和layout_marginTop中都使用了“-10dp”,这使您的取消按钮脱离了对话框布局(我希望,您知道这一点)@mustafiz012 ok bro。。谢谢。@NileshRathod嘿,我看到了你的个人资料,我想知道你为什么把世界上最好的人链接到我的个人资料上?这真是一个伟大的赞美:D