2012-03-22 51 views
0

我正在嘗試使用佈局來定製我的警報對話框。問題在於ALert對話框是小型的,大部分佈局都是分開的或者單詞重疊。這不是屏幕問題,因爲對話框非常小,似乎不能擴展以覆蓋所有內容。你爲什麼認爲這是發生?爲什麼我的警報對話框沒有顯示其所有內容

我使用以下佈局:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 

    <LinearLayout 
     android:id="@+id/linearLayout2" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_above="@+id/linearLayout1" 
     android:layout_alignParentLeft="true" 
     android:orientation="horizontal" > 

     <TextView 
      android:id="@+id/tvNa" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="0.5"/> 

     <EditText 
      android:id="@+id/etNa" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" /> 
    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/linearLayout1" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_centerVertical="true" 
     android:orientation="horizontal" > 

     <TextView 
      android:id="@+id/tvQ" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="0.5"/> 

     <EditText 
      android:id="@+id/etQ" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" /> 

    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/linearLayout3" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_below="@+id/linearLayout1" 
     android:layout_centerVertical="true" 
     android:orientation="horizontal" > 

     <TextView 
      android:id="@+id/tvP" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="0.5" /> 

     <EditText 
      android:id="@+id/etP" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:inputType="numberDecimal" /> 

    </LinearLayout> 

</RelativeLayout> 

,我使用下面的代碼:

AlertDialog.Builder alert = new AlertDialog.Builder(this); 
LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 

View layout = inflater.inflate(R.layout.add_dialog, null); 
alert.setView(layout); 
alert.setTitle("New one"); 
alert.setPositiveButton("Ok",new DialogInterface.OnClickListener() { 
@Override 
    public void onClick(DialogInterface dialog, int whichButton) { 


    } 
}); 
alert.setNegativeButton("Cancel",new DialogInterface.OnClickListener() { 
@Override 
    public void onClick(DialogInterface dialog, int whichButton) { 

    } 
}); 
alert.show(); 
+0

'alert.setContentView(R.layout.add_dialog)' – 2012-03-22 17:31:14

+0

它不存在。這是警報對話框,不是對話框。它有setView和我上面使用它 – Snake 2012-03-22 17:46:50

回答

0

對話框對象有,你有沒有寫上設置最大尺寸。您可以將您的佈局添加到ScrollView。除此之外,您必須遵循Dialog的繼承,直到找到設置最大對話框大小的位置並覆蓋此設置。 GrepCode是查看SDK源代碼的好地方。

相關問題