android -custom对话框,关闭按钮一半外面

时间:2015-03-04 09:59:10

标签: android dialog popup android-dialogfragment

我想创建如屏幕所示的DialogFragment,问题是在对话框外创建关闭按钮。

Close button overflow outside of popup

2 个答案:

答案 0 :(得分:4)

使用此代码进行自定义对话框。

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

答案 1 :(得分:0)

将内容放入单独的布局中,以便Button和内容布局是另一种布局中的兄弟,如下所示:

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

现在给内容布局android:padding,比方说20dp。同时,按下按钮android:alignParentTopandroid:alignParentRight

这应该按照你想要的方式工作

相关问题