Android DialogFragment 布局,奇怪的额外空白

标签 android layout dialogfragment

所以在为一个简单的“让用户选择”弹出窗口制作了一个 dialogfragment 之后,我加载了它并在布局中看到了一些奇怪的额外空白,我不确定是什么原因造成的,我已经一直在绞尽脑汁想弄明白。我稍微修改了 xml 以更好地显示行为,唯一的区别是我将 3 个垂直部分的宽度从“match_parent”更改为“wrap_content”,因此我可以使用边框来显示空白的实际大小.这是显示问题的图片:

the problem

这是我的 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 布局是否缺少某些内容?我每次都可以手动设置宽度的大小,但我更希望窗口本身实际上是“wrap_content”

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

最佳答案

罪魁祸首是标题。设置:

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

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

关于Android DialogFragment 布局,奇怪的额外空白,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20308359/

相关文章:

java.lang.OutOfMemory错误: bitmap size exceeds VM budget

android - 具有 `layout_weight` 和 `maxWidth` 的灵活水平布局

android - 对话框 fragment 中的自动完成 TextView 显示 Android 中的建议

android - 从 DialogFragment 和主 Activity 更新 RecyclerView

Android Layout Listview在relativelayout下的高度调整

android - 更新按钮上的文本

android - 在导航图 NavGraph 中找不到与请求 NavDeepLinkRequest 匹配的导航目的地

java - Android TextView 不更新 View

android - layout-large-v11 和 layout-xlarge 有什么区别

html - 如何在图片右侧放置文字?