Android对话框片段布局,奇数额外空格

Android对话框片段布局,奇数额外空格,android,layout,dialogfragment,Android,Layout,Dialogfragment,因此,在为一个简单的“让用户选择”弹出窗口制作了一个dialogfragment之后,我加载了它,并在布局中看到了一些奇怪的额外空白,我不确定是什么导致了它,我一直在绞尽脑汁试图找出它。我稍微修改了xml以更好地显示行为,唯一的区别是我将3个垂直部分的宽度从“匹配父项”更改为“换行内容”,以便使用边框显示空白的实际大小。以下是显示问题的图片: 以下是我的xml: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmln

因此,在为一个简单的“让用户选择”弹出窗口制作了一个
dialogfragment
之后,我加载了它,并在布局中看到了一些奇怪的额外空白,我不确定是什么导致了它,我一直在绞尽脑汁试图找出它。我稍微修改了xml以更好地显示行为,唯一的区别是我将3个垂直部分的宽度从“匹配父项”更改为“换行内容”,以便使用边框显示空白的实际大小。以下是显示问题的图片:

以下是我的xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/pictureSourceMainTextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/tvborder"
        android:gravity="center"
        android:text="Where would you like to choose\nyour image from?"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <LinearLayout
        android:id="@+id/pictureSourceIVLayout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/tvborder"
        android:weightSum="3" >

        <ImageView
            android:id="@+id/pictureSourceCancelIV"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:src="@drawable/ic_launcher" />

        <ImageView
            android:id="@+id/pictureSourceGalleryIV"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:src="@drawable/ic_launcher" />

        <ImageView
            android:id="@+id/pictureSourceCameraIV"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:src="@drawable/ic_launcher" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/pictureSourceTVLayout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:weightSum="3" >

        <TextView
            android:id="@+id/pictureSourceCancelTV"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@drawable/tvborder"
            android:gravity="center"
            android:text="Cancel" />

        <TextView
            android:id="@+id/pictureSourceGalleryTV"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_weight="1"
            android:background="@drawable/tvborder"
            android:gravity="center"
            android:text="Gallery" />

        <TextView
            android:id="@+id/pictureSourceCameraTV"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_weight="1"
            android:background="@drawable/tvborder"
            android:gravity="center"
            android:text="Camera" />
    </LinearLayout>

</LinearLayout>

所以我的问题是:我能做些什么来删除这个额外的空白?我的xml布局缺少什么吗?我可以每次手动设置宽度的大小,但我更希望窗口本身实际上是“包装内容”


编辑:大小调整是由标题引起的,有没有办法将标题缩小到合适的大小?

TextView
android:layout\u width
更改为
“fill\u parent”

您还可以将android:gravity=“center”添加到外部
线性布局

罪魁祸首就是标题。设置:

getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE); 

在我的对话框中的
oncreateview
中,Fragment修复了所有大小问题,我只是在顶部添加了一个新的
imageview
,并在photoshop中设计了我自己的标题。

试着从xml编辑器的“图形布局”选项卡中查找额外的空间是什么?您已经在实际的
布局中为您的
宽度
匹配了父视图,包括根视图
LinearLayout
?@user251182无需查看,在xml编辑器中也无需查看there@codeMagic:我将三个对象从“match_parent”更改为“wrap_content”以演示空白,它们是:“PictureSourceIntextView、pictureSourceIVLayout和pictureSourceTVLayout”,恢复为“match_parent”它填满了额外的空间,但我不想这样,我想把它包装成内容的大小,那么你想在空白处做什么呢?另外,在您的第二个孩子
LinearLayout
中,您应该有
android:layout\u height=“0dp”
,因为您使用的是
weight