Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/220.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android DialogFragment不';t包装内容_Android_Listview_Android Listview_Android Dialogfragment_Android Dialog - Fatal编程技术网

Android DialogFragment不';t包装内容

Android DialogFragment不';t包装内容,android,listview,android-listview,android-dialogfragment,android-dialog,Android,Listview,Android Listview,Android Dialogfragment,Android Dialog,单击TextView时,会显示一个对话框片段。这个对话框片段有自己的XML布局文件,在底部有一个列表视图,以及一个编辑文本和按钮 问题是,当列表视图只有几个项目时,对话框片段仍然占据了屏幕的大部分(即高度远大于其应有的高度) 这是我的意思的屏幕截图(黑色是带有一个项目的列表视图): 正如您所看到的,当我希望对话框仅为其所需大小时,列表视图上方有大量空白 以下是对话框fRagentXML: <RelativeLayout xmlns:android="http://schemas.

单击
TextView
时,会显示一个
对话框片段。这个
对话框片段
有自己的XML布局文件,在底部有一个
列表视图
,以及一个
编辑文本
按钮

问题是,当
列表视图
只有几个项目时,
对话框片段
仍然占据了屏幕的大部分(即高度远大于其应有的高度)

这是我的意思的屏幕截图(黑色是带有一个项目的
列表视图
):

正如您所看到的,当我希望
对话框
仅为其所需大小时,
列表视图上方有大量空白

以下是
对话框fRagent
XML:

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="@dimen/spacing_small"
    tools:context="com.cohenadair.anglerslog.fragments.ManageFragment">

    <LinearLayout
        android:id="@+id/add_item_layout"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true">

        <EditText
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:id="@+id/new_item_edit"
            android:layout_weight="1"
            android:hint="@string/hint_new_item"/>

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/button_add"
            android:id="@+id/add_button"
            android:layout_margin="0dp"/>

    </LinearLayout>

    <ListView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@id/add_item_layout"
        android:id="@+id/content_list_view"
        android:background="@android:color/black">

    </ListView>

</RelativeLayout>

谢谢!

我通过从
RelativeLayout
切换并使用
LinearLayout
layout\u weight
属性解决了这个问题

以下是新的XML:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="@dimen/spacing_small"
    android:orientation="vertical"
    tools:context="com.cohenadair.anglerslog.fragments.ManageFragment">

    <ListView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:id="@+id/content_list_view">

    </ListView>

    <LinearLayout
        android:id="@+id/add_item_layout"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <EditText
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:id="@+id/new_item_edit"
            android:layout_weight="1"
            android:hint="@string/hint_new_item"/>

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/button_add"
            android:id="@+id/add_button"/>

    </LinearLayout>

</LinearLayout>


但是,RelativeLayout的问题仍然存在。@DevetiPutnik正确。我始终无法找出
RelativeLayout
不起作用的原因,或者使用
RelativeLayout
找到正确的解决方案。这个答案显然只是一个解决办法。
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="@dimen/spacing_small"
    android:orientation="vertical"
    tools:context="com.cohenadair.anglerslog.fragments.ManageFragment">

    <ListView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:id="@+id/content_list_view">

    </ListView>

    <LinearLayout
        android:id="@+id/add_item_layout"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <EditText
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:id="@+id/new_item_edit"
            android:layout_weight="1"
            android:hint="@string/hint_new_item"/>

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/button_add"
            android:id="@+id/add_button"/>

    </LinearLayout>

</LinearLayout>