首页 > 解决方案 > 我的对话框现在填充了整个高度,而不是环绕内容

问题描述

我正在尝试使用一个对话窗口,人们可以在其中填写一些信息。但我遇到的问题是它的高度(而不是宽度)填满了我的整个屏幕。 对话

这是我的布局文件:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@drawable/dialog_bg"
    tools:context=".UI.Main.Create.CreateStoryDialogFragment">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        //some fields

    </LinearLayout>
</RelativeLayout>

我在 DialogFragment 中使用了这一行:

dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));

有人可以说我哪里出错了吗?

标签: androidxml

解决方案


如果android:layout_height="wrap_content"您想通过其内容包装视图,则使用它,如果您替换android:layout_height="match_parent"布局 XML 中的所有内容,它应该可以工作。

您可能需要将 替换RelativeLayoutFrameLayout.


推荐阅读