简体   繁体   English

带有关闭按钮一半的android -custom对话框

[英]android -custom dialog with close button half outside

I want to create DialogFragment like shown in screen, the problem is to create close button outside of the dialog. 我想创建如屏幕所示的DialogFragment,问题是在对话框外部创建关闭按钮。

关闭按钮在弹出窗口之外溢出

Use this code for making custom dialog. 使用此代码进行自定义对话框。

<?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"
 android:orientation="vertical" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_margin="25dp"
    android:background="#111111" >
</LinearLayout>

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:src="@drawable/ic_home" />

</RelativeLayout>

Put the contents into a separate layout so that the Button and the contents layout are siblings in another layout, like this: 将内容放入单独的布局中,以便Button和content布局是另一个布局中的同级对象,如下所示:

<RelativeLayout>
    <RelativeLayout               //Contents, the list etc.
        android:padding="20dp"
        />   
    <Button                       //Your close Button
        android:alignParentTop="true"
        android:alignParentRight="true"
        />           
</RelativeLayout>

Now give the contents layout a android:padding , lets say 20dp. 现在给内容布局一个android:padding ,比如说20dp。 At the same time, give the Button android:alignParentTop and android:alignParentRight . 同时,给Button android:alignParentTopandroid:alignParentRight

This should work the way you want it to 这应该按照您想要的方式工作

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

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