2

我想创建一个自定义对话框,其中包含列表视图和列表视图下方的按钮。按钮应位于列表视图下方,但始终可见(layout_alignParentBottom="true")。

我创建了一个运行良好的 xml,但仅限于长列表。如果列表很短,按钮仍然在屏幕底部,并且对话框标题的高度被拉伸以使对话框填满屏幕。附图显示了我今天得到的。

简而言之。我想要一个仅在必要时才填满屏幕的普通对话框。

由于某种原因,我无法发布 xml。但我使用相对布局,按钮对齐父底部,小面板布局在按钮上方,列表视图布局在此面板上方。所有布局都是 layout:height=wrap_content。

感谢您的帮助。/马格纳斯

替代文字

4

3 回答 3

6

这个答案通常是正确的,但由于许多嵌套布局而引入了显着的开销。

您需要的是LinearLayout具有特定配置的简单:

<ListView
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
     />
<!-- Notice layout_weight=1 and height=0dp - it's the most important thing here-->


<WhateverLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >
<!-- And the layout below the listview has some arbitrary height (but no weight!)-->

</WhateverLayout>

</LinearLayout>

结果是一样的:“对话框不大于内容,最大与屏幕一样大,按钮始终可见。”

于 2013-08-06T18:48:06.607 回答
3

问题已经解决了。

我从 android 源代码中获取了alert_dialog.xml并对其进行了一些修改。我将我的列表视图添加到 customPanel 框架布局中,删除了 topPanel 和 contentPanel。

结果:对话框不大于内容,最大与屏幕一样大,按钮始终可见。

于 2011-01-14T13:42:11.277 回答
1

回答@Fresh_Meat

您可以像这样将按钮添加到列表视图的底部: http ://www.anddev.org/code-snippets-for-android-f33/listview-with-a-footer-item-t49281.html

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:orientation="vertical"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   android:padding="10dip"
   >
    <LinearLayout
        android:id="@+id/bottom_view"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true">
            <!--Put whatever view item you want here -->
            <EditText
             android:id="@+id/conversation_reply"
             android:layout_width="fill_parent"
             android:layout_height="wrap_content"
             android:text="write a reply..."
             />
   </LinearLayout>
   <ListView
    android:id="@+id/android:list"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:cacheColorHint="#00000000"
    android:layout_above="@id/bottom_view"
    />
</RelativeLayout>

带页脚的列表

在您的警报视图中使用它

于 2011-02-22T14:36:29.520 回答