2013-05-03 57 views
1

我必須顯示幫助信息,如何使用該程序的說明,我選擇AlertDialog使用自定義XML與ScrollView。我在平板電腦,xperia neo和2個虛擬設備上測試過。其中3個很好,但在2.3小屏幕下,對話框太大並且在可視化中存在一個錯誤,使得它很難關閉。任何想法爲什麼? 這裏是我的代碼: XML爲滾動型:自定義AlertDialog滾動查看,在2.3太大缺少確定按鈕

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" > 
    <TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:textSize="10sp"> 
    </TextView> 
</ScrollView>` 

而且我調用它的代碼:

AlertDialog.Builder builder = new AlertDialog.Builder(this); 
    builder.setMessage(R.string.msg_help) 
      .setCancelable(false) 
      .setView(LayoutInflater.from(this).inflate(R.layout.dialog_scrollable,null)) 
      .setTitle(R.string.help_title) 
      .setPositiveButton("OK", new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog, int id) { 
        //do things 
       } 
      }); 
    AlertDialog alert = builder.create(); 
    alert.getWindow().setLayout(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); 
    alert.show(); 

下面是它的外觀:http://postimg.org/image/wvg61x0qv/

回答

1

AlertDialog使其內容如果它不適合在屏幕上自動滾動。您只需將文本設置爲與 builder.setText() builder.setMessage()對話,而不是將自定義XML佈局膨脹。

AlertDialog.Builder builder = new AlertDialog.Builder(this); 
builder.setMessage(R.string.msg_help) 
     .setCancelable(false) 
     .setTitle(R.string.help_title) 
     .setMessage(R.string.help) 
     .setPositiveButton("OK", new DialogInterface.OnClickListener() { 
      public void onClick(DialogInterface dialog, int id) { 
       //do things 
      } 
     }); 
AlertDialog alert = builder.create(); 
alert.show(); 

請注意,我還與alert.getWindow().setLayout()刪除線,因爲我認爲這是沒有用的。

+0

感謝它與setMessage()完美的工作; – Roi 2013-05-03 12:21:47

+0

儘管我建議使用一種不可用的方法,但很高興幫助您。 :)感謝您的更正。我也在頂部的文本中糾正了它。 – zbr 2013-05-03 12:34:10