我想用AlertDialog下面的按鈕顯示一個列表。按鈕是關閉對話框本身。我擴展AlertDialog
並添加了一些LayoutParams
到Window
延長整個屏幕寬度的對話框:AlertDialog中的ListView下的按鈕被隱藏
//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
,但該按鈕不顯示在其下。這裏是對話框的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>
我該怎麼做才能在列表中顯示按鈕ALWAYS,不管它多長時間? (我讀了很多警告,把一個ListView
一個ScrollView
內,嘗試也無妨和失敗...)
在alertdialog上使用'setPositiveButton',就是這麼做的。 – njzk2