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>