【发布时间】:2014-02-10 20:26:13
【问题描述】:
我想在 AlertDialog 中显示一个带有按钮的列表。该按钮是关闭对话框本身。我扩展了AlertDialog并在Window中添加了一些LayoutParams来扩展整个屏幕宽度的Dialog:
//Grab the window of the dialog, and change the width
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
Window window = getWindow();
lp.copyFrom(window.getAttributes());
//This makes the dialog take up the full width
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
window.setAttributes(lp);
好的。但如果列表很长(显示已满),我可以滚动ListView,但按钮不会显示在其下方。这是 Dialog 的 ContentView:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/choose_equipment_list"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:layout_below="@+id/choose_equipment_list"
android:id="@+id/btn_choose_equipment_close"
style="@style/custom_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="close" />
</RelativeLayout>
我该怎么做才能在列表下始终显示按钮,无论它有多长? (我读了很多警告,将ListView 放在ScrollView 中,无论如何都尝试过但失败了......)
【问题讨论】:
-
在警报对话框上使用
setPositiveButton,这就是它的用途。
标签: android listview scrollview scrollable