列表视图和按钮的自定义对话框始终为全屏

Mag*_*nus 2 android listview dialog button android-alertdialog

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

我已经创建了一个非常好用的xml,但仅限于长列表.如果列表很短,则按钮仍位于屏幕底部,并且对话框标题的高度将拉伸以生成对话框填充屏幕.附图显示了我今天得到的结果.

简而言之.我想要一个普通的对话框,如果nececcary只填充屏幕.

我出于某种原因无法发布xml.但是我使用了relativelayout,按钮对齐父母底部,小面板布置在按钮上方,listview布置在此面板上方.所有布局都是布局:height = wrap_content.

感谢任何帮助./马格努斯

替代文字

Mic*_*ł K 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>
Run Code Online (Sandbox Code Playgroud)

结果是一样的:"一个不大于内容的对话框,最大的屏幕大小,总是按钮可见."