gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 15:36:20 24 4
gpt4 key购买 nike

所以在为一个简单的“让用户选择”弹出窗口制作了一个 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com